如果你遇到了“Babel插件未应用于node_module”的错误,这通常是因为Babel配置未正确地应用于node_modules中的依赖项。以下是一些常见的解决方法:
确保你在项目的根目录下有一个有效的Babel配置文件(例如.babelrc
或babel.config.js
)。
检查你的Babel配置文件是否正确地指定了要使用的插件和预设。确保你已经在配置文件中包含了适用于node_modules的插件和预设。例如,你可以尝试将以下内容添加到你的配置文件中:
{
"plugins": ["@babel/plugin-transform-runtime"],
"presets": ["@babel/preset-env"]
}
babel-loader
来转译你的代码,确保你已经在Webpack配置中正确地应用了Babel配置。你可以在Webpack配置文件中的module.rules
中添加以下代码:{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime']
}
}
}
注意,上面的代码假设你已经安装了相应的Babel插件和预设。
希望以上解决方法能帮助你解决问题!