gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'locals' of undefined

转载 作者:行者123 更新时间:2023-12-03 23:11:27 27 4
gpt4 key购买 nike

我制作了 bundle.js 和 bundle.css 以在我的网络应用程序中使用,
我的 package.json 看起来像这样:

  "dependencies": {
"bootstrap": "^4.5.3",
"jquery": "^3.5.1",
"popper.js": "^1.16.1"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/preset-env": "^7.12.11",
"babel-loader": "^8.2.2",
"css-loader": "^5.0.1",
"file-loader": "^6.2.0",
"mini-css-extract-plugin": "^1.3.3",
"node-sass": "^5.0.0",
"sass-loader": "^10.1.0",
"style-loader": "^2.0.0",
"url-loader": "^4.1.1",
"webpack": "^5.11.0",
"webpack-cli": "^4.2.0"
},
我的 webpack.config.js:
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = (env, argv) => {
return {
//Define entry point
entry: ['./src/index.js', './src/css/index.scss'],

//Define output point
output: {
path: path.resolve(__dirname, 'wwwroot/dist'),
filename: 'bundle.js'
},

module: {
rules: [
{
test: /\.s[c|a]ss$/,
include: path.resolve(__dirname, 'src'),
use: [
'style-loader',
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
},
{
test: /\.js$/,
include: path.resolve(__dirname, 'src'),
loader: 'babel-loader',
options: {
presets: ["@babel/preset-env"],
plugins: ['@babel/plugin-proposal-object-rest-spread']
}
},
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
new MiniCssExtractPlugin({
filename: 'bundle.css'
})
]

};
};
我的 src 结构是这样的:
src
index.js:
import 'jquery';
import 'bootstrap';
import './js/login';
import './js/helpers';
索引.scss:
@import 'bootstrap';
@import 'util.scss';
@import 'login.scss';
@import 'site.css';
我在控制台中收到此错误:
Console
bundle.js
其他一切都工作正常,我对 javascript 没有任何问题,但我不知道如何解决这个错误,这让我很烦恼。
PS:
我一般是 web 开发的新手,昨天开始使用 webpack,想法是在我的 html 中只使用 bundle.js 和 bundle.css 而不为它们分别添加 jquery 和 bootstrap 标签

最佳答案

尝试将 MiniCssExtractPlugin 的选项 esModule 设置为 false

use: [
'style-loader',
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false,
},
},
'css-loader',
'sass-loader'
]

关于javascript - 未捕获的类型错误 : Cannot read property 'locals' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65359841/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com