我使用https://github.com/babel/babel-upgrade升级到Babel 7,现在出现与grunt / browserify相关的错误。
在咕unt声文件中:
browserify: {
options: {
watch: true,
transform: [['babelify', {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [
['@babel/plugin-transform-react-jsx', {'pragma':'h'}]
],
}]],
browserifyOptions: {
standalone: 'Viewer', // Set name of package as window global when no package system is present
debug: true // Enables Source Maps
}
},
all: {
options: {
watch: true, // Listen for incremental changes to files (fast incremental build)
},
files: {
...
}
}
} . . .
我在“ browserify:all”上遇到以下错误:
错误:需要Babel“ ^ 7.0.0-0”,但已加载“ 6.26.3”。如果您确定拥有@ babel / core的兼容版本,则可能是您的构建过程中正在加载错误的版本。检查此错误的堆栈跟踪,以查找第一个未提及“ @ babel / core”或“ babel-core”的条目,以了解正在调用的Babel。 (同时处理预设:“ XXXX”)时,解析文件:“ XXXXXX”
有人可以帮我解决这个问题吗?
package.json:
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-do-expressions": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-bind": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"grunt-browserify": "^5.3.0",
"jest": "^23.5.0",
"jsdom": "^12.1.0"
},
"dependencies": {
"@tweenjs/tween.js": "^17.3.0",
"autoprefixer": "^6.7.5",
"babelify": "^7.3.0",
"browserify": "^13.1.0",
"cssnano": "^3.10.0",
"diff-arrays-of-objects": "^1.1.2",
"eslint": "^3.7.1",
"eslint-plugin-react": "^6.10.3",
"filesize": "^3.6.1",
"grunt": "^1.0.2",
"grunt-contrib-uglify-es": "^3.3.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-env": "^0.4.4",
"grunt-eslint": "^19.0.0",
"grunt-open": "^0.2.4",
"grunt-postcss": "^0.8.0",
"grunt-sass": "^2.1.0",
"mathjs": "^5.4.0",
"p-queue": "^3.0.0",
"preact": "^8.2.7",
"preact-range-slider": "^0.2.0",
"preact-redux": "^2.0.1",
"redux": "^3.6.0",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.2.0",
"redux-undo": "^1.0.0-beta9-9-7",
"tslib": "^1.9.0",
"tween": "^0.9.0"
}
答案 0 :(得分:1)
1-删除节点模块
npm install rimraf -g
rimraf node_modules
2-将"babelify": "^7.3.0"
升级到"babelify": "^9.0.0"
(Babelify 7.3.0加载babel-core v 6.26.3)
3-将"babel-preset-es2015"
和"babel-preset-react
更改为
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0"
(如果使用它们)
4-在.babelrc
中,将"presets": ["react", "es2015"]
更改为"presets": ["@babel/preset-env", "@babel/preset-react"]
(如果使用的话)
5-npm install
答案 1 :(得分:0)
尝试删除您的node_modules
文件夹,然后重新运行npm install
-这将删除旧版本中的所有依赖项遗留。
答案 2 :(得分:0)
当您运行grunt文件时,它正在寻找babel注册。但是,对于babel 7.0.0和更高版本,您需要它查找@ babel / register。因此,您需要安装@ babel / register,它应该可以正常工作,而无需您采取任何进一步的措施。
npm install --save-dev @babel/register