Vue开玩笑找不到通天塔 [英] Vue-jest can't find babel
问题描述
我正在尝试测试vue组件,但是我总是遇到以下错误:
I'm trying to test my vue components however I'm always getting the following error:
在对象上找不到模块"babel-core". (node_modules/vue-jest/lib/compilers/babel-compiler.js:1:15)
Cannot find module 'babel-core' at Object. (node_modules/vue-jest/lib/compilers/babel-compiler.js:1:15)
package.json:
package.json:
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"@vue/test-utils": "^1.0.0-beta.29",
"babel-jest": "^24.1.0",
"babel-loader": "^8.0.5",
"css-loader": "^2.1.0",
"file-loader": "^3.0.1",
"jest": "^24.1.0",
"mini-css-extract-plugin": "^0.5.0",
"node-sass": "^4.11.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"vue": "^2.6.6",
"vue-jest": "^3.0.3",
"vue-loader": "^15.6.2",
"vue-router": "^3.0.2",
"vue-template-compiler": "^2.6.6",
"webpack": "^4.29.3",
},
.babelrc
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-syntax-dynamic-import"
]
}
jest.config.js
jest.config.js
module.exports = {
verbose: true,
moduleFileExtensions: [ "js", "json", "jsx", "ts", "tsx", "node", "vue" ],
transform: {
// process js with `babel-jest`
"^.+\\.js$": "babel-jest",
// process `*.vue` files with `vue-jest`
".*\\.(vue)$": "vue-jest",
}
};
您可以在此处看到这种行为.
You can see this behaviour here.
查看引用的文件时,我可以看到:
When looking at the referenced file I can see:
const babel = require('babel-core')
那不是@babel/core
吗?
所以我的问题是如何解决该错误?还是这是vue-jest
出现的问题?
So my question is how can I resolve the error? Or is this an issue comming from vue-jest
?
推荐答案
按照@JamesCoyle的建议,安装babel-bridge
即可解决
As suggested by @JamesCoyle installing babel-bridge
solved it
npm i -D babel-core@^7.0.0-bridge.0
这篇关于Vue开玩笑找不到通天塔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!