Unexpected token import
Closed this issue · 3 comments
WellerQu commented
It works fine but working with mocha. When I execute
cross-env NODE_ENV=production mocha --compilers js:babel-register,js:./test/css-complier.js -t 10000 -s 1000 --inline-diffs --growl --colors --harmony --recursive ./test/setup.js ./test/**/*.spec.js
I use the decorator like this:
import React, { Component } from 'react';
import { autobind } from 'core-decorators';
class Foo extends Component {
@autobind
next() {
// do something
}
}
then, I get an error:
import _Object$defineProperty from 'babel-runtime/core-js/object/define-property';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at loader (/Users/qiuwei/Workspace/rongcaptial-ui/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/qiuwei/Workspace/rongcaptial-ui/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/qiuwei/Workspace/rongcaptial-ui/src/core/index.js:1:1)
at Module._compile (module.js:571:32)
at loader (/Users/qiuwei/Workspace/rongcaptial-ui/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/qiuwei/Workspace/rongcaptial-ui/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/qiuwei/Workspace/rongcaptial-ui/src/index.js:7:13)
at Module._compile (module.js:571:32)
at loader (/Users/qiuwei/Workspace/rongcaptial-ui/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/qiuwei/Workspace/rongcaptial-ui/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/qiuwei/Workspace/rongcaptial-ui/test/core/collectionView.spec.js:9:12)
Could you help me, please? Thanks
jayphelps commented
From the provided details this sounds like an issue with mocha + babel stuff, not core-decorators. I'm afraid I can't help! Lmk if I'm mistaken (provide more clarification please)
WellerQu commented
@jayphelps Thank you 👍 , I will check my code again.
WellerQu commented
@jayphelps I found the different. It gets that error if I set NODE_ENV=production, but set NODE_ENV=development not.