Jest failed Unexpected token } in JSON at position 441 Vue2 Typescript
See original GitHub issueVersion
1.3.0
Reproduction link
Steps to reproduce
run yarn test.
What is expected?
run correctly the test
What is actually happening?
Shows the next 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/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
SyntaxError: Unexpected token } in JSON at position 441
at JSON.parse (<anonymous>)
at parse (node_modules/tsconfig/src/tsconfig.ts:195:15)
at readFileSync (node_modules/tsconfig/src/tsconfig.ts:181:10)
at Object.loadSync (node_modules/tsconfig/src/tsconfig.ts:151:18)
at find (node_modules/vue-jest/lib/load-typescript-config.js:33:39)
at loadTypescriptConfig (node_modules/vue-jest/lib/load-typescript-config.js:73:26)
at compileTypescript (node_modules/vue-jest/lib/compilers/typescript-compiler.js:9:20)
at processScript (node_modules/vue-jest/lib/process.js:23:12)
at Object.module.exports [as process] (node_modules/vue-jest/lib/process.js:42:18)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:620:31)
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
Jest encountered an unexpected token when testing a Vue ...
The solution to my problem turns out to be a bit anti-climatic. The problem was that my regexp string to recognize .vue files...
Read more >jest encountered an unexpected token uuid - You.com | The AI ...
JEST - SyntaxError: Unexpected token 'export' with uuid library ... It is failing on the import of the .scss from logon.tsx: import styles...
Read more >What Is JSON and How to Handle an “Unexpected Token” Error
Learn what JSON is and how you can deal with errors occurring when parsing JSON data, such as "Unexpected Token < in JSON...
Read more >Jest throwing `SyntaxError: Unexpected token import` on new ...
You should not run jest directly, but instead run it with the command that vue-cli defined for you in package.json. If you run...
Read more >TypeScript Jest: Unexpected Token Export - Reddit
Ok so now your test project is using common JS, but node sees your dependency as an ES Module, so it throws an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Add to the jest.config.js
transformIgnorePatterns: [‘/node_modules/(?!library-with-problems)’]
if you have a trailing comma anywhere in your ts-config file do take it off… that was what fixed my problem…