jayphelps / core-decorators

Library of stage-0 JavaScript decorators (aka ES2016/ES7 decorators but not accurate) inspired by languages that come with built-ins like @​override, @​deprecate, @​autobind, @​mixin and more. Popular with React/Angular, but is framework agnostic.
MIT License
4.52k stars 263 forks source link

Unexpected token import #131

Closed WellerQu closed 7 years ago

WellerQu commented 7 years ago

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 7 years ago

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 7 years ago

@jayphelps Thank you 👍 , I will check my code again.

WellerQu commented 7 years ago

@jayphelps I found the different. It gets that error if I set NODE_ENV=production, but set NODE_ENV=development not.