vue + jest + typescript: Unexpected token import
See original GitHub issueHi all, I have a Typescript file which imports a Vue file. It seems vue-jest doesn’t like this?
/path-to-my-project/Autocomplete/Autocomplete.vue:14
import ItemTemplate from './_autocomplete_item.vue';
^^^^^^
SyntaxError: Unexpected token import
> 1 | import Autocomplete from './Autocomplete/Autocomplete.vue';
| ^
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
at Object.<anonymous> (path-to-my-project/base.ts:1:1)
You’ll note that it’s able to find Autocomplete.vue
, but is unable to parse the import within Autocomplete.vue
.
Here is my jest config; Am I doing something obviously wrong here?
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.vue$": "vue-jest"
},
"testRegex": "(\\./test/javascript/.*|\\.(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"vue",
"js",
"jsx",
"json",
"node"
]
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Jest encountered an unexpected token when testing a Vue ...
This usually means that you are trying to import a file which Jest cannot parse, e. ... g. it's not plain JavaScript. By...
Read more >Test Vue with Jest fail, Jest encountered an unexpected token ...
Coding example for the question Test Vue with Jest fail, Jest encountered an unexpected token, SyntaxError: Unexpected token import-Vue.js.
Read more >How I Fixed The Unexpected Token Error In Jest
Depending upon your setup, you might see the error on the first line of the code file or you might see it when...
Read more >test suite failed to run jest encountered an unexpected token
This means that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it...
Read more >Jest throwing `SyntaxError: Unexpected token import` on new ...
Jest throwing `SyntaxError: Unexpected token import` on new Vue CLI ... Not sure what in means, seems like some internal problem. Anyone seen...
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
I finally found a way to make it work 🎉🎉🎉 by adding these lines to the
jet.config.js
:Thanks to: https://stackoverflow.com/questions/53397773/node-modules-not-being-parsed-correctly-for-tests/53414070#53414070
I also had to add
"allowJs": true,
to mytsconfig.json
I hope it can help you out!
Any news on this issue ? I also get this error 👎