SyntaxError: Unexpected token import on fresh project
See original GitHub issueVersion
3.0.0-beta.15
Reproduction link
Steps to reproduce
- vue create vue-project
- cd vue-project
- jest tests/unit/HelloWorld.spec.js --no-cache
What is expected?
The test case is executed with no errors
What is actually happening?
Test suite failed to run
Adding the following block to babel.config.js
fixes this particular error
env: {
test: {
presets: ['@babel/env'],
},
},
but it raises another error: http://take.ms/jlxuP
And this happens because import
doesn’t work for some reason.
When I change
import HelloWorld from '@/components/HelloWorld.vue';
to
const HelloWorld = require('../../src/components/HelloWorld.vue').default;
it works fine: http://take.ms/ILHes
P.S. Unaliased import doesn’t work as well:
import HelloWorld from '../../src/components/HelloWorld.vue';
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:18 (4 by maintainers)
Top Results From Across the Web
Node.js - SyntaxError: Unexpected token import - Stack Overflow
Node.js - SyntaxError: Unexpected token import · 4. Use transpiler like Babel to use import in Nodejs as it is not natively supported...
Read more >SyntaxError: Unexpected token 'export' in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, ... Open your terminal in your project's root directory and run the following command....
Read more >syntaxerror unexpected token 'export' typescript - You.com
So the dependency in node_modules folder exports a function using ES6 import/export module. The code will throw error when it running in browser...
Read more >Unexpected Token Export: A Comprehensive Guide
– “Type” Property Set to “Module” in the package. · – Properly Import the Class Into Another File · – Use the Common....
Read more >How to fix SyntaxError: Unexpected token 'export' in JavaScript?
There is another reason why this error occurred when we try to work with ES6 modules. And that is we don't tell the...
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
Yes, it’s under
~/.npm
Typescript does not know how to handle vue files, therefore you need to place the following code in your index.d.ts fiile
declare module '*.vue' { import Vue from 'vue'; export default Vue; }