从 test_helper 编译失败
failed compile from test_helper
我写了 test_helper 来测试我的反应组件,但每次我点击 npm start
并出现以下错误。
> jsonplaceholder-client@0.0.1 test /Users/WOOJUNG/Desktop/jsonplaceholder-client
> mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test
/Users/WOOJUNG/Desktop/jsonplaceholder-client/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/index.js:573
throw err;
^
SyntaxError: /Users/WOOJUNG/Desktop/jsonplaceholder-client/test/test_helper.js: Unexpected token (21:4)
19 | function renderComponent(ComponentClass, props = {}, state = {}) {
20 | const componentInstance = TestUtils.renderIntoDocument(
> 21 | <Provider store={createStore(reducers, state)}>
| ^
22 | <ComponentClass {...props} />
23 | </Provider>
24 | );
似乎是编译失败导致的错误test_helper
。我不确定,但据我所知 js:babel-core/register
可以编译 es6 但失败了。我应该给另一个选项来编译 test_helper
吗?但我不知道。 T_T
要么在你的package.json文件中有你的.babelrc配置,如下
{
"name": "my-package",
"version": "1.0.0",
"babel": {
"presets": ["react", "es2015", "stage-1"]
}
}
或
如果你的应用程序文件夹,请确保你在根目录中有 .babelrc。与其他配置相同的级别。文件
我的 .babelrc 看起来像
{
"presets": ["react", "es2015", "stage-1"]
}
我写了 test_helper 来测试我的反应组件,但每次我点击 npm start
并出现以下错误。
> jsonplaceholder-client@0.0.1 test /Users/WOOJUNG/Desktop/jsonplaceholder-client
> mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test
/Users/WOOJUNG/Desktop/jsonplaceholder-client/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/index.js:573
throw err;
^
SyntaxError: /Users/WOOJUNG/Desktop/jsonplaceholder-client/test/test_helper.js: Unexpected token (21:4)
19 | function renderComponent(ComponentClass, props = {}, state = {}) {
20 | const componentInstance = TestUtils.renderIntoDocument(
> 21 | <Provider store={createStore(reducers, state)}>
| ^
22 | <ComponentClass {...props} />
23 | </Provider>
24 | );
似乎是编译失败导致的错误test_helper
。我不确定,但据我所知 js:babel-core/register
可以编译 es6 但失败了。我应该给另一个选项来编译 test_helper
吗?但我不知道。 T_T
要么在你的package.json文件中有你的.babelrc配置,如下
{
"name": "my-package",
"version": "1.0.0",
"babel": {
"presets": ["react", "es2015", "stage-1"]
}
}
或
如果你的应用程序文件夹,请确保你在根目录中有 .babelrc。与其他配置相同的级别。文件
我的 .babelrc 看起来像
{
"presets": ["react", "es2015", "stage-1"]
}