我想建立一個基本的模塊化程序,但我似乎遇到導入模塊的問題。我試圖導入我的自定義模塊,我得到以下錯誤巴貝爾ES6導入錯誤,SyntaxError:意外的令牌導入
(function (exports, require, module, __filename, __dirname) { import testStep from 'testStep';
^^^^^^
SyntaxError: Unexpected token import
導致該問題的代碼:
testcase.js
import testStep from 'testStep';
testStep.hello();
testStep.js
var testStep = {
hello: hello,
};
var hello =() => {
console.log('hello world');
};
export default {testStep};
package.json
{
"name": "rebuild-poc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.6.0"
},
"dependencies": {}
}
.babelrc
{
"presets": [
"env"
]
}
我已經嘗試過其他幾個補丁,比如設置一步步測試,作爲一個階級,以及使用要求(」 ./ testStep.js'),但那些都似乎已經工作了。
我有什麼東西與babel或我的文件之一設置不正確嗎?
***編輯:我正在運行testCase.js與 '節點testCase.js'
看起來像'testStep'中有一個額外的括號或額外逗號 – Matthew
'import'不能在一個函數內 –
@Meshe在es6尾隨逗號是允許的,但我試過了,它刪除了,它沒有修復問題。 –