我正在使用express-react-views包在serverside(NodeJs)中渲染react组件。我尝试渲染示例https://github.com/reactjs/express-react-views/tree/master/examples/dynamic中的react组件。但是当我尝试npm start时,它抛出了一个错误: 错误:需要Babel“ ^ 7.0.0-0”,但已加载“ 6.26.3”。我尝试根据https://github.com/babel/babel-upgrade上的文档升级babel。但是仍然存在相同的错误。
如何解决此问题?请帮忙,因为我在此错误上遇到问题
我的package.json文件
{
"name": "dynamic-views",
"version": "0.1.0",
"description": "Example of creating a dynamic app using express-react-
views",
"author": "Chris Johnson <tenorviol@yahoo.com>",
"private": true,
"scripts": {
"start":
"browserify -t babelify views/main.js --standalone main -o
public/main.js && node app.js"
},
"dependencies": {
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babelify": "^7.3.0",
"browserify": "^14.3.0",
"express": "^4.15.3",
"express-react-views": "^0.11.0",
"react": "^16.0.0",
"react-dom": "^16.0.0"
}
}
我的package-lock.json文件
{
"name": "dynamic-views",
"version": "0.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@babel/code-frame": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-
frame-7.0.0.tgz",
"integrity": "sha512- OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==",
"requires": {
"@babel/highlight": "^7.0.0"
}
},
"@babel/core": {
"version": "7.4.5",
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.4.5.tgz",
"integrity": "sha512-OvjIh6aqXtlsA8ujtGKfC7LYWksYSX8yQcM8Ay3LuvVeQ63lcOKgoZWVqcpFwkd29aYU9rVx7jxhfhiEDV9MZA==",
"requires": {
"@babel/code-frame": "^7.0.0",
"@babel/generator": "^7.4.4",
"@babel/helpers": "^7.4.4",
"@babel/parser": "^7.4.5",
"@babel/template": "^7.4.4",
"@babel/traverse": "^7.4.5",
"@babel/types": "^7.4.4",
"convert-source-map": "^1.1.0",
"debug": "^4.1.0",
"json5": "^2.1.0",
"lodash": "^4.17.11",
"resolve": "^1.3.2",
"semver": "^5.4.1",
"source-map": "^0.5.0"
}
},
答案 0 :(得分:0)
我发现this post对下面的错误有很大的帮助。 :)
Jest TypeError: Path must be a string. Received undefined
TypeError: Cannot read property 'cwd' of undefined
对我来说,以下解决方案有效。我希望它也对您有用!
yarn add babel-jest@22.4.3 --dev
yarn add jest@21.0.2 --dev
babel-core@^7.0.0-0
---> (Choose "7.0.0-bridge.0")