当我运行npm test
(jest --watch
)时,我得到:
C:\sites\YDR\branches\trunk\development\app\static\js\_modules\marketplace\postbacks\Components\Form.js:44
import('Form').then(function (m) {
^^^^^^
SyntaxError: Unexpected token import
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
at Object.<anonymous> (__tests__/postbacks-form.js:1:115)
开玩笑的 package.json 的一部分:
"jest": {
"rootDir": "./../../",
"modulePaths": [
"<rootDir>tools/webpack/node_modules/",
"<rootDir>development/app/static/css/_modules/",
"<rootDir>development/app/static/js/_modules/"
],
"transform": {
"^.+\\.js$": "<rootDir>/tools/webpack/jest.transform.js"
}
}
jest.transform.js:
// Custom Jest transform implementation that wraps babel-jest and injects our
// babel presets, so we don't have to use .babelrc.
module.exports = require('babel-jest').createTransformer({
presets: [
require("babel-preset-react"),
require("babel-preset-es2015")
],
plugins: [
require("babel-plugin-syntax-dynamic-import"),
]
});
我正在使用以下版本:
- 节点@8.1.3
- npm@5.3.0
- 开玩笑@20.0.4
- babel-core@6.25.0
- babel-jest@20.0.3
- babel-plugin-syntax-dynamic-import@6.18.0
我也试过 babel-plugin-dynamic-import-node@1.0.2,但是我有不同的错误:
Plugin 0 specified in "base" provided an invalid property of "default"