gpt4 book ai didi

node.js - Babel 预设 ENV 问题

转载 作者:搜寻专家 更新时间:2023-11-01 00:05:00 26 4
gpt4 key购买 nike

美好的一天:

我刚刚通过 NPM 安装了 Babel Preset-ENV 并遇到了这个问题:

[nodemon] starting `babel-node server.js server.js`
/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328
throw e;
^

TypeError: Cannot read property 'loose' of undefined (While processing preset: "/home/vagrant/api/node_modules/@babel/preset-env/lib/index.js")
at _default (/home/vagrant/api/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js:19:22)
at Function.memoisePluginContainer (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
at Function.normalisePlugin (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
at /home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (native)
at Function.normalisePlugins (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at /home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
at /home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
at Array.map (native)

我的 Package.JSON 如下:

{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon -L server.js --ignore 'db/schema.json' --exec babel-node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@babel/core": "^7.0.0-beta.32",
"@babel/preset-env": "^7.0.0-beta.32",
"babel-core": "^6.26.0",
"express": "^4.16.2",
"express-graphql": "^0.6.11",
"express-oauth-server": "^2.0.0",
"graphql": "^0.11.7",
"jsonwebtoken": "^8.1.0",
"mongo": "^0.1.0",
"mongoose": "^4.13.2",
"password-hash": "^1.2.2",
"react-relay": "^1.4.1"
},
"devDependencies": {
"babel-cli": "^6.26.0"
}
}

还有我的 .babelrc 是这样的:

vagrant@vagrant-ubuntu-trusty-64:~/api$ cat .babelrc 
{
"presets": [
["@babel/preset-env", {
"targets": {
"node": "current"
}
}]
]
}

在升级之前,我使用的是 stage-0es2015 预设,但是在升级之后,这一直是错误的。注意,我的 NPM 版本是 4.6.1

谢谢。

最佳答案

确保您的 Babel 依赖项彼此兼容。

这个:

"@babel/core": "^7.0.0-beta.32",
"@babel/preset-env": "^7.0.0-beta.32",
"babel-core": "^6.26.0",
"babel-cli": "^6.26.0"

应该是这样的:

"@babel/cli": "^7.0.0-beta.34",
"@babel/core": "^7.0.0-beta.34",
"@babel/node": "^7.0.0-beta.34",

关于node.js - Babel 预设 ENV 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47283235/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com