Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected token import on fresh project #1475

Closed
matrunchyk opened this issue Jun 5, 2018 · 18 comments
Closed

SyntaxError: Unexpected token import on fresh project #1475

matrunchyk opened this issue Jun 5, 2018 · 18 comments
Labels
needs reproduction This issue is missing a minimal runnable reproduction, provided by the author

Comments

@matrunchyk
Copy link

Version

3.0.0-beta.15

Reproduction link

http://take.ms/A60B9

Steps to reproduce

  1. vue create vue-project
  2. cd vue-project
  3. 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';
@matrunchyk
Copy link
Author

So I suppose the initial issue will be gone once we add @babel/env preset to test environment on vue cli 3 generator. Any idea how to fix the 2nd one with export?

@yyx990803
Copy link
Member

Can't reproduce. Please provide an actual reproduction: a repository that we can look into.

@yyx990803 yyx990803 added the needs reproduction This issue is missing a minimal runnable reproduction, provided by the author label Jun 5, 2018
@matrunchyk
Copy link
Author

matrunchyk commented Jun 5, 2018

Sure: https://github.com/matrunchyk/vue-cli-1475

Thanks for so fast feedback!

@yyx990803
Copy link
Member

Oh actually, you are not supposed to run jest directly. Use the test:unit npm script.

@matrunchyk
Copy link
Author

Alt text

@matrunchyk
Copy link
Author

@yyx990803 it is still the same.

@matrunchyk
Copy link
Author

matrunchyk commented Jun 5, 2018

@yyx990803
Copy link
Member

yyx990803 commented Jun 5, 2018

Unfortunately I can't reproduce this using your exact repo.
What is your OS / Node / npm version?

@matrunchyk
Copy link
Author

matrunchyk commented Jun 5, 2018

npm -v

6.1.0

node -v

v8.11.1

@yyx990803
Copy link
Member

I did try with the exact same Node and npm versions with your repo and cannot reproduce it.
This may have something to do with your npm caching.

@matrunchyk
Copy link
Author

Yeah, it was something to do with my cache. Now it's gone. Sorry for taking your time.

@martosoler
Copy link

Ok, so I'm having a similar issue @matrunchyk ... what cache are you referring to? NPM?

@matrunchyk
Copy link
Author

Yes, it's under ~/.npm

@next-nurialopez
Copy link

Hi @matrunchyk , I'm getting the same error, what did you do to clean the cache?

@matrunchyk
Copy link
Author

@beeva-nurialopez rm -rf ~/.npm

@next-nurialopez
Copy link

next-nurialopez commented Oct 2, 2018 via email

@matrunchyk
Copy link
Author

See #1584 discussion

@JuanGrauGGG
Copy link

Version

3.0.0-beta.15

Reproduction link

http://take.ms/A60B9

Steps to reproduce

  1. vue create vue-project
  2. cd vue-project
  3. 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';

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; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reproduction This issue is missing a minimal runnable reproduction, provided by the author
Projects
None yet
Development

No branches or pull requests

5 participants