我正在尝试使用一个简单的引导程序,jquery插件bootstrap-show-password
,但是在加载表单页面时显示了一个错误的Uncaught ReferenceError: $ is not defined
。
我不明白为什么不加载jquery。我照常做了
npm install bootstrap jquery popper.js --save
在我的app.js
里我有
//import jQuery from "jquery";
//window.$ = window.jQuery = jQuery;
// this should be loaded with webpack, right?! ^
import "bootstrap";
import "bootstrap-show-password";
我看到的是webpack的docs,它说要使用插件提供程序,但是当我把它添加到我的webpack.config.js
中时
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
});
npm run build
给我TypeError: webpack.ProvidePlugin is not a constructor
错误
我是不是遗漏了需要安装的东西?
下面是我的package.json
依赖项
"devDependencies": {
"@babel/preset-env": "^7.12.17",
"autoprefixer": "^9.8.6",
"babel-loader": "^8.2.2",
"browser-sync": "^2.26.14",
"eslint": "^7.20.0",
"eslint-loader": "^4.0.2",
"htmlnano": "^0.2.8",
"imagemin-cli": "^6.0.0",
"node-sass": "^5.0.0",
"npm-run-all": "^4.1.5",
"onchange": "^7.1.0",
"postcss": "^8.2.6",
"postcss-cli": "^8.3.1",
"posthtml": "^0.15.1",
"posthtml-cli": "^0.9.1",
"posthtml-modules": "^0.7.3",
"stylelint": "^13.11.0",
"webpack": "^5.23.0",
"webpack-cli": "^4.5.0"
},
"dependencies": {
"bootstrap": "^4.6.0",
"bootstrap-show-password": "^1.2.1",
"jquery": "^3.5.1",
"popper.js": "^1.16.1"
}
发布于 2021-02-21 03:48:02
好的,几个小时后,我发现罪魁祸首在webpack.config.js
中被错误地初始化了webpack
变量。出于我无法理解的原因,我在那里
const { webpack } = require("webpack");
而不是
const webpack = require("webpack");
https://stackoverflow.com/questions/66293449
复制相似问题