2016-03-11 155 views
4

步驟:npm test運行摩卡測試導致「意外的保留字」錯誤

錯誤:「意外的保留字」

我有這個今天早些時候的工作,我不知道什麼是我改變了這一切可能造成迴歸。當我運行npm test時,我收到「意外的保留字」,它指向一個ES6導入語句。我的理解是--compilers js:babel-register應該解決這個問題。

我已經嘗試在全球和本地安裝babel-core,並使用babel-core/register來代替。同樣的結果。

這是我的package.json

{ 
    "name": "fresh", 
    "version": "0.0.1", 
    "private": true, 
    "scripts": { 
    "remotedev": "remotedev --hostname=localhost --port=8000", 
    "start": "node node_modules/react-native/local-cli/cli.js start", 
    "test": "mocha --compilers js:babel-register 'test/**/*.test.js'", 
    "test:watch": "npm run test -- --watch --watch-extensions jsx" 
    }, 
    "dependencies": { 
    "immutable": "^3.7.6", 
    "lodash": "^4.5.1", 
    "ramda": "^0.19.1", 
    "react-native": "^0.21.0", 
    "react-native-router-flux": "^2.3.8", 
    "react-native-sortable-listview": "0.0.5", 
    "react-redux": "^4.4.0", 
    "redux": "^3.3.1", 
    "redux-saga": "^0.9.1", 
    "reselect": "^2.0.3" 
    }, 
    "devDependencies": { 
    "babel-register": "^6.7.2", 
    "chai": "^3.5.0", 
    "chai-immutable": "^1.5.3", 
    "mocha": "^2.4.5", 
    "redux-devtools-filter-actions": "^1.1.0", 
    "remote-redux-devtools": "^0.1.2", 
    "remotedev-server": "0.0.3" 
    } 
} 

這裏是2個教程指出這應該工作。

https://onsen.io/blog/mocha-chaijs-unit-test-coverage-es6/

http://jamesknelson.com/testing-in-es6-with-mocha-and-babel-6/

我又一次成功執行今天早些時候與該腳本的測試。

+0

我碰到同樣的問題。你有沒有解決這個問題,@ ken4z? – Hypaethral

回答

1
npm install babel-preset-es2015 

然後創建.babelrc文件,

{ 
    "presets": ["es2015"] 
} 
+0

謝謝你的迴應。我已經嘗試過了,連同其他幾個babel預設都無濟於事。 – ken4z

相關問題