【发布时间】:2021-11-19 02:04:45
【问题描述】:
当我运行“webpack”命令时,我得到了这个错误:
./js/main.js 中的错误 未找到模块:错误:无法解析 '...\js' @ ./js/main.js 中的 'jquery' 3:0-16 4:0-23
在 package.json 我有:
"devDependencies": {
"handlebars": "^4.0.6",
"handlebars-loader": "^1.4.0",
"jquery": "^3.2.1",
"path": "^0.12.7"
},
在 webpack.config.js 中:
var path = require("path");
module.exports = {
entry: "./js/main.js",
output: {
path: __dirname + "/js",
filename: "scripts-bundled.js"
},
resolve: {
modules: [
path.join(__dirname, "js/helpers")
]
},
module: {
loaders: [
{test: /\.hbs$/, loader: "handlebars-loader"}
]
}
};
在文件顶部的 main.js 中,我有:
import $ from 'jquery';
我还在 main.js 中使用把手。难道是车把或车把加载器干扰了jquery?我之前在另一个没有使用把手的项目中使用过 webpack 和 jquery 没有这个问题,但可能与它无关。
【问题讨论】:
-
据我所知,你应该使用 JQLITE 来将 jquery 与 webpack 一起使用
标签: jquery webpack handlebars.js