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

@vue/babel - dynamic import fail #922

Closed
maxpou opened this issue Mar 2, 2018 · 4 comments
Closed

@vue/babel - dynamic import fail #922

maxpou opened this issue Mar 2, 2018 · 4 comments
Labels

Comments

@maxpou
Copy link

maxpou commented Mar 2, 2018

Version

3.0.0-beta.2

Reproduction link

maxpou/gitvub#43

Steps to reproduce

  1. vue create test-dyn-import
  2. pick vue-router, vuex, sass, babel, pwa, eslint, unit-jest
  3. add new file users.json under test/unit
{
  "data": ["bob", "max"]
}
  1. add the following test
  it('should import my file', async () => {
    const userFile = './users.json'
    const users = await import(userFile)
    console.log(users)
  })
  1. run npm run test

What is expected?

test should be green and print something like this { data: [ 'bob', 'max' ] }

What is actually happening?

~/sites/lab/test-dyn-import(master*) » npm run test

> test-dyn-import@0.1.0 test /home/maxence/sites/lab/test-dyn-import
> vue-cli-service test

 FAIL  tests/unit/HelloWorld.spec.js
  ● Test suite failed to run

    /home/maxence/sites/lab/test-dyn-import/tests/unit/HelloWorld.spec.js:35
                return import(userFile).then(function (someModule) {
                       ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.488s
Ran all test suites.
 ERROR  jest exited with code 1.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-dyn-import@0.1.0 test: `vue-cli-service test`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test-dyn-import@0.1.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/maxence/.npm/_logs/2018-03-02T17_51_40_312Z-debug.log

I'm trying to switch to the new file architecture for one of my side project (https://github.com/maxpou/gitvub).
I solved this issue with the past architecture by the following babelrc file

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
      }
    }],
    "stage-2"
  ],
  "plugins": ["transform-runtime"],
  "env": {
    "test": {
      "presets": ["env", "stage-2"],
      "plugins": ["transform-es2015-modules-commonjs", "dynamic-import-node"]
    }
  }
}
@yyx990803 yyx990803 added the bug label Mar 2, 2018
@yyx990803
Copy link
Member

Looks like we need to enable dynamic-import-node for test environments in the preset.

@maxpou
Copy link
Author

maxpou commented Mar 3, 2018

Thanks!
@yyx990803, I forget to say thank you for this new vue-cli. You definitely gonna make our life easier 👍

@petr-k
Copy link

petr-k commented May 24, 2018

The exact same error still happens with 3.0.0-beta.11.
Settings used:

Manually select features
---
Babel
Router
CSS Pre-processors
Linter / Formatter
Unit testing
---
LESS
---
ESLint + Prettier
---
Jest
---
config: In dedicated config files

@yyx990803 Would mind taking a look? Thanks ;)

@yyx990803
Copy link
Member

@petr-k can't reproduce. Please open separate issue with proper reproduction.

@vuejs vuejs locked and limited conversation to collaborators May 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants