[英]webpack - Module not found: Error: Can't resolve 'jquery'
I'm using Sails 1 with webpack and when I attempt to import jquery from my main js file, I get this error yelling that it can't resolve jquery. 我正在将Sails 1与webpack一起使用,当我尝试从主js文件导入jquery时,我大喊这个错误,无法解决jquery。
webpack.config.js: webpack.config.js:
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports.webpack = {
devtool: 'source-map',
entry: {
'admin': './assets/admin/js/admin.js'
},
output: {
filename: 'js/[name].bundle.js',
path: path.resolve(__dirname, '..', '.tmp', 'public')
},
resolve: {
modules: [
path.join(__dirname, "js"), "node_modules"
]
},
module: {
// Extract less files
rules: [{
test: /\.css$/,
loader: ExtractTextPlugin.extract({ use: 'css-loader' })
}, {
test: /\.less$/,
loader: ExtractTextPlugin.extract({ use: 'css-loader!less-loader' })
}, {
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
[ 'es2015', { modules: false } ]
]
}
}]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
// This plugin extracts CSS that was imported into .js files, and bundles
// it into separate .css files. The filename is based on the name of the
// .js file that the CSS was imported into.
new ExtractTextPlugin('css/[name].bundle.css'),
// This plugin cleans out your .tmp/public folder before lifting.
new CleanWebpackPlugin(['public'], {
root: path.resolve(__dirname, '..', '.tmp'),
verbose: true,
dry: false
}),
// This plugin copies the `images` and `fonts` folders into
// the .tmp/public folder. You can add any other static asset
// folders to this list and they'll be copied as well.
new CopyWebpackPlugin([{
from: './assets/images',
to: path.resolve(__dirname, '..', '.tmp', 'public', 'images')
}])
]
};
and in my assets/admin/js/admin.js I only have 在我的资产/admin/js/admin.js中,我只有
import 'jquery';
jquery is on my package json and it shows up under my node_modules packages with the name jquery . jQuery在我的包json上,并显示在我的node_modules包下,名称为jquery 。
Another weird thing is that if I change jquery and attempt to import angular , it works perfectly, so I don't think it's a node_modules directory issue or something like that. 另一个奇怪的是,如果我改变jQuery和尝试导入的角度 ,它完美的作品 ,所以我不认为这是一个node_modules目录问题,或者类似的东西。
A different issue brought me here. 一个不同的问题把我带到了这里。 For future visitors coming from Google, try running:
对于将来来自Google的访问者,请尝试运行:
webpack --display-error-details
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.