我的 webpack proyect 有问题,所以我试图将一个类导入另一个类并实例化它,但突然在我的控制台中出现错误并且我的程序停止工作,是这样的:
Uncaught ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization
Run Code Online (Sandbox Code Playgroud)
这是我尝试导入另一个类(即 PopUpPlugin)时的类代码:
import PopupPlugin from './popupPlugin.js';
export const addSearchBtnEvent = (weatherUI) => {
const searchBtn = document.querySelector('.weather__search');
searchBtn.addEventListener('click', () => {
weatherUI.style.opacity = '1';
weatherUI.style.visibility = 'visible';
})
}
export const addSearchExitEvent = (weatherUI) => {
const weatherExit = document.querySelector('.weather__search-exit');
weatherExit.addEventListener('click', () => {
weatherUI.style.opacity = '0';
weatherUI.style.visibility = 'hidden';
})
}
const popupObj = new PopupPlugin();
class searchDashboard {
constructor() {
}
setInputEvent() {
const inputSearch = document.querySelector('.weather__city-search'); …Run Code Online (Sandbox Code Playgroud) 所以我在尝试编译时在我的 webpack 代码中收到此错误,当我以生产模式启动时会发生这种情况,当我删除 html-loader 时,错误消失了,我还包括要使用的 HtmlWebpackPlugin 和 file-loader :
webpack.prod.js:
const path = require("path");
const common = require('./webpack.common.js');
const { merge } = require('webpack-merge');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = merge(common, {
mode: "production",
output: {
publicPath: '',
filename: "js/[name].[contenthash].bundle.js",
path: path.resolve(__dirname, "dist")
},
plugins: [
new CleanWebpackPlugin()
]
});
Run Code Online (Sandbox Code Playgroud)
webpack.common.js:
const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
main: "./src/index.js"
},
plugins: [
new HtmlWebpackPlugin({
template: './src/html/index.html'
})
],
module: {
rules: …Run Code Online (Sandbox Code Playgroud) webpack webpack-html-loader html-webpack-plugin webpack-file-loader