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

ava and "Unexpected token import" #58

Open
MoOx opened this issue Mar 25, 2016 · 9 comments · Fixed by #59
Open

ava and "Unexpected token import" #58

MoOx opened this issue Mar 25, 2016 · 9 comments · Fixed by #59

Comments

@MoOx
Copy link
Contributor

MoOx commented Mar 25, 2016

Hi,

I am trying to run tests with AVA and your plugin.
At the first place, it wasn't working (error below). I rm -rf node_modules, then tried again and it was working (tests on jsx and react were failing as expected). No idea why, I changed a string in my file, and got this error:

Uncaught Exception: /Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/web_modules/Button/__tests__/index.js
  SyntaxError: /Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/web_modules/Button/__tests__/index.js: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at localInteropRequire (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-plugin-webpack-loaders/lib/plugin.js:211:13)
    at PluginPass.CallExpression (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-plugin-webpack-loaders/lib/plugin.js:41:135)
    at newFn (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/visitors.js:262:19)
    at NodePath._call (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/path/context.js:63:18)
    at NodePath.call (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/path/context.js:47:17)
    at NodePath.visit (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/path/context.js:93:12)
    at TraversalContext.visitQueue (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/context.js:152:16)
    at TraversalContext.visitSingle (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/context.js:115:19)
    at TraversalContext.visit (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/context.js:184:19)

I reverted my changes but same problem.

Note that I run with the following command (I just pasted interesting part)

{
  "scripts": {
    "ava": "CONFIG=$(pwd)/webpack.config.test.babel.js BABEL_DISABLE_CACHE=1 NODE_ENV=test ava",
    "test": "npm run lint && npm run ava"
  },
  "babel": {
    "presets": [
      "babel-preset-react",
      "babel-preset-es2015",
      "babel-preset-stage-1"
    ],
    "env": {
      "production": {
        "plugins": [
          "babel-plugin-react-remove-prop-types"
        ]
      },
      "test": {
        "plugins": [
          [
            "babel-plugin-webpack-loaders",
            {
              "config": "${CONFIG}",
              "verbose": false
            }
          ]
        ]
      }
    }
  },
  "ava": {
    "files": [
      "web_modules/**/__tests__/*.js"
    ],
    "failFast": true,
    "verbose": true,
    "require": [
      "babel-register"
    ],
    "babel": "inherit"
  },

I cannot share my webpack config as it's very messy and private, just be sure that I use this

// import normal config
import webpackConfig from "./webpack.config.babel.js"

export default {
  ...webpackConfig,

  // babel-plugin-webpack-loaders requirements
  entry: undefined,
  output: {
    libraryTarget: "commonjs2",
  },
}
@MoOx
Copy link
Contributor Author

MoOx commented Mar 25, 2016

Looks like a cache issue. I tried deleting node_modules/.cache/ava but no luck. Babel cache is supposed to not be used according to BABEL_DISABLE_CACHE.

@istarkov
Copy link
Owner

looks like for some reason it does not expect that index.js is es6 module. Will try today to add ava to tests.

@istarkov
Copy link
Owner

Also sometimes I got problems with this presets sequence

 "babel-preset-react",
  "babel-preset-es2015",
  "babel-preset-stage-1"

and now prefer
es, stage, react

(it's undependent of plugin, but some of my code does not compile with your presets sequence)

@istarkov
Copy link
Owner

Good news, I've reproduced this error.

@istarkov istarkov mentioned this issue Mar 25, 2016
@istarkov
Copy link
Owner

Thank you, fixed, 0.4.0 in npm (I have no idea why it worked before even on mocha)

I'm not sure that current fix is good (or I'm sure it's not a good idea to call babel-register inside plugin) (the better is to require config in some isolated env) but all tests working fine and ava too.

@istarkov istarkov reopened this Mar 25, 2016
@thangngoc89
Copy link

I'm sure it's not a good idea to call babel-register inside plugin

Yeah. I'm concern about this too. What if I have babel-register inside the code ?

@istarkov
Copy link
Owner

Tests have babel-register now, and looks like all fine, if it will be a problem I'll rewrite this
on node vm module to run webpack config in 'sandboxed' env. (I did this in local versions but got that all works fine and removed that code)

@DmitryOlkhovoi
Copy link

DmitryOlkhovoi commented Apr 21, 2016

I have this issue in case:

babel-plugin-webpack-loader:
js and jsx files in loaders is unsupported by webpack-loader plugin.
all babel settings in loader will be skipped

Why it skips babel settings? :)

@istarkov
Copy link
Owner

It skips babel settings in webpack loaders. Not all babel setting.
Why it skips them in laoders - because this plugin is not intended to create client bundles. On server imports can be imported-required without webpack support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants