Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Jest encountered an unexpected token - Unexpected token 'export'#3621

Unanswered
loralameh asked this question inQ&A
Discussion options

I am trying to run a jest test on my functions that are using "googleapis" and get the following error
`
Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.By default "node_modules" folder is ignored by transformers.Here's what you can do: • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it. • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config. • If you need a custom transformation specify a "transform" option in your config. • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.You'll find more details and examples of these config options in the docs:https://jestjs.io/docs/configurationFor information about custom transformations, see:https://jestjs.io/docs/code-transformationDetails:/app/node_modules/googleapis-common/node_modules/uuid/dist/esm-browser/index.js:1({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from './v1.js';                                                                                  ^^^^^^SyntaxError: Unexpected token 'export'

`

I have tried adding

  transform: {    '^.+\\.(t)s$': 'ts-jest',    '^.+\\.(js|jsx)$': 'babel-jest'  }  transformIgnorePatterns: ['/node_modules/(?!googleapis|googleapis-common/)']

but this did not solve the problem

I am using

"googleapis": "105","jest": "^29.7.0","babel-jest": "^29.7.0","ts-jest": "^29.1.4"

so mainly from what i understand from the problem and what i have researched that googleapis is using googleapis-common node module and they have not pre-compiled their node module into standard JS with module.exports instead of export {} syntax,

NOTE: I do not want to mock the 'googleapis'

You must be logged in to vote

Replies: 1 comment

Comment options

Hi there, this is an environment question - moving this to discussions.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@loralameh@sofisl
Converted from issue

This discussion was converted from issue #3501 on February 08, 2025 01:45.


[8]ページ先頭

©2009-2025 Movatter.jp