Jest 不断警告 "Cannot use import statement outside a module"
Jest keeps warning "Cannot use import statement outside a module"
看起来像是导入模块错误。
这是我的 package.json 设置,任何人都可以指出我缺少什么吗?
谢谢
{
"name": "prj",
"version": "1.0.0",
"scripts": {
"dev": "vite --port 8080",
"build": "vite build",
"serve": "vite preview --port 8000",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest"
},
"jest": {
"moduleFileExtensions": ["js", "json", "vue"],
"transform": {
"^.+\.js$": "babel-jest",
"^.+\.vue$": "vue-jest"
}
},
"dependencies": {
"axios": "^0.21.1",
"vue": "^3.2.6",
"vue-i18n": "^9.1.7",
"vue-router": "^4.0.11",
"vuex": "^4.0.2"
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@vitejs/plugin-vue": "^1.6.0",
"@vue/compiler-sfc": "^3.0.5",
"@vue/test-utils": "^2.0.0-rc.14",
"babel-jest": "^26.6.3",
"vite": "^2.5.1",
"vue-jest": "^5.0.0-alpha.10"
}
}
ExperimentalWarning:VM 模块是一项实验性功能。此功能可能随时更改
(使用 node --trace-warnings ...
显示创建警告的位置)
失败 src/tests/examples.test.js
● 测试套件未能 运行
Jest encountered an unexpected token
......
Details:
/some/path/src/tests/examples.test.js:4
import HomePage from './src/views/HomePage.vue';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
我正在使用 webpack 并且遇到了与我修复安装 babel-core bridge 时相同的错误:
npm install --save-dev babel-core@^7.0.0-bridge.0
我还需要 jest.config.js 中的以下一个:
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/',
},
看起来像是导入模块错误。 这是我的 package.json 设置,任何人都可以指出我缺少什么吗? 谢谢
{
"name": "prj",
"version": "1.0.0",
"scripts": {
"dev": "vite --port 8080",
"build": "vite build",
"serve": "vite preview --port 8000",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest"
},
"jest": {
"moduleFileExtensions": ["js", "json", "vue"],
"transform": {
"^.+\.js$": "babel-jest",
"^.+\.vue$": "vue-jest"
}
},
"dependencies": {
"axios": "^0.21.1",
"vue": "^3.2.6",
"vue-i18n": "^9.1.7",
"vue-router": "^4.0.11",
"vuex": "^4.0.2"
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@vitejs/plugin-vue": "^1.6.0",
"@vue/compiler-sfc": "^3.0.5",
"@vue/test-utils": "^2.0.0-rc.14",
"babel-jest": "^26.6.3",
"vite": "^2.5.1",
"vue-jest": "^5.0.0-alpha.10"
}
}
ExperimentalWarning:VM 模块是一项实验性功能。此功能可能随时更改
(使用 node --trace-warnings ...
显示创建警告的位置)
失败 src/tests/examples.test.js
● 测试套件未能 运行
Jest encountered an unexpected token
......
Details:
/some/path/src/tests/examples.test.js:4
import HomePage from './src/views/HomePage.vue';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
我正在使用 webpack 并且遇到了与我修复安装 babel-core bridge 时相同的错误:
npm install --save-dev babel-core@^7.0.0-bridge.0
我还需要 jest.config.js 中的以下一个:
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/',
},