我正在使用jQuery作为对等依赖项的插件。当我尝试将此插件导入我的主项目(已经安装了jQuery)时,出现了错误Module not found: Error: Can't resolve 'jquery' in <(plugin's folder)>
。看来,当我尝试动态导入jQuery(对等依赖项)node_modules
时node_modules
,即使它是对等依赖项,Webpack也在编译时在插件的文件夹中查找,而不是在根项目的文件夹中。我怎样才能让webpack在根项目node_modules
而不是插件中查找node_modules
?
Webpack.config.js:
var webpack = require('webpack');
module.exports = {
entry: './main.js',
output: {
filename: 'bundle.js'
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
],
watch: true,
resolve: {
alias: { jquery: "jQuery" }
}
};
我想我通过将其添加到我的webpack配置resolve
选项中找到了解决方案:
modules: [
path.resolve('./node_modules'),
path.resolve('../node_modules')
]
编辑:实际上,从我实际上从npm导入项目后,问题似乎完全消失了,而在我使用npm链接之前。不再需要上述解决方案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句