Nuxtjs-全新安装的nuxt2.14.6包含babel“宽松选项”警告
我全新安装了 2.14.6 版的 nuxt,我想消除运行 nuxt 命令时出现的错误:
WARN Though the "loose" option was set to "false" in your @babel/preset-env co
The "loose" option must be the same for @babel/plugin-proposal-class-properties,
["@babel/plugin-proposal-private-methods", { "loose": true }]
to the "plugins" section of your Babel config.
我假设我需要覆盖我的 nuxt.config.js 文件中的 babel 配置,但我还没有找到任何有用的解决方案。
回答
将以下内容添加到nuxt.config.js该build部分下的文件中。
nuxt.config.js
build: {
babel:{
plugins: [
['@babel/plugin-proposal-private-methods', { loose: true }]
]
}
}
回答
我宁愿重置nuxt回2.15.2并等待它修复。虽然上面的答案在短期内修复了它,但在新的 nuxt 安装中的那些警告对我来说看起来像是一个错误。
-
Upvoted. It's always good to make sure you aren't silencing something you might actually care about, without fully understanding the ramifications.
Don't mind me while I add this to my Babel config for now though... 😀
- Why? The current behavior is a bug (warnings on a fresh install), and it's a solution until a fixed version is available.
- 就像 SO 上的往常一样,这只是模组有动力旅行。坦率地说,这个答案对我来说至关重要
回答
尝试在 nuxt.config.js 中添加这些:
build: {
babel:{
plugins: [
["@babel/plugin-proposal-class-properties", { "loose": true }],
["@babel/plugin-proposal-private-methods", { "loose": true }],
["@babel/plugin-proposal-private-property-in-object", { "loose": true }]
]
}
},
- `@babel/plugin-proposal-private-property-in-object` 就足够了,不需要全部都拥有。
回答
Nuxt 2.15.7 的最新更新
看起来最新版本又出现了一些错误,更多信息可以在这里找到最新的 Nuxt v2.15.7 install with babel "loose" option warnings
这个问题是从 Nuxt 修复的,v2.15.5如这个 github 问题中所述:https : //github.com/nuxt/nuxt.js/issues/9224#issuecomment-835742221
您可以删除任何resolutions与build.babel.plugins关系到你的这个错误nuxt.config.js配置。此外,如果需要,您应该重置:
yarn.lock(或package-lock.json)node_modules/.cache.nuxt
THE END
二维码