TypeError: ((process.env.NODE_ENV === "production") && [MiniCssExtractPlugin]) is not iterable
299
작성한 질문수 9
TypeError: ((process.env.NODE_ENV === "production") && [MiniCssExtractPlugin]) is not iterable
문제 없어보이는데 계속 저 에러가 발생하네요
npm run build 만 입력하면 production이 아니니까 타야할거같은데 환경변수를 집어넣어주면 에러가 발생안하고 안넣어주면 에러가 발생합니다.
const path = require("path");
const webpack = require("webpack");
const childProcess = require("child_process");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const isProduction = process.env.NODE_ENV === "production";
module.exports = {
mode: "development",
entry: {
mainSrc: "./app.js",
},
output: {
path: path.resolve("./dist"),
filename: "[name].js",
},
module: {
rules: [
{
test: /\.css$/,
use: isProduction
? [MiniCssExtractPlugin.loader, "css-loader"]
: ["style-loader", "css-loader"],
},
{
test: /\.(png|jpg|gif|svg)$/,
type: "asset/resource",
},
{
test: /\.js$/,
loader: "babel-loader",
exclude: "/node_modules/",
},
],
},
plugins: [
new webpack.BannerPlugin({
banner: `
Build Date : ${new Date().toLocaleString()}
Commit Version : ${childProcess.execSync("git rev-parse --short HEAD")}
Author : ${childProcess.execSync("git config user.name")}
`,
}),
new webpack.DefinePlugin({
TWO: "1+1",
TWO_STRING: JSON.stringify("1+1"),
"api-domain": JSON.stringify("http://dev.api.domain.com"),
}),
new HtmlWebpackPlugin({
template: "./src/index.html",
templateParameters: {
env: process.env.NODE_ENV === "development" ? "개발용" : "운영",
},
minify: process.env.NODE_ENV === "production" && {
collapseWhitespace: true,
removeComments: true,
},
}),
new CleanWebpackPlugin(),
...(process.env.NODE_ENV === "production" && [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
]),
],
};
답변 1
0
코드 맨 아래 플러그인 지정하는 부분에서 발생한 원인이네요.
...(process.env.NODE_ENV === "production" && [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
]), 첫 번째 표현식이 false 이기 때문에 전체 문장은 false가 될 겁니다. [...false] 로 평가되어 불리언 타입에 나머지 연산을 시도하다가 TypeError 가 발생했을 것 같아요.
삼항 연산자로 한 번 바꿔보시겠습니까?
...(mode === "production"
? [new MiniCssExtractPlugin({ filename: `[name].css` })]
: [])
지금 시점에서 해당 강의를 듣는 것에 대하여
1
109
3
2025년 기준 번들러 트렌드와 선택 기준이 궁금합니다 (Webpack, Vite, tsup 등)
1
218
1
에러 해결 공유드립니다
1
223
2
webpack 4 버전과 호환되는 플러그인 버전 공유드립니다
1
232
2
eslint
0
379
3
도와주세요!
0
165
2
[수강 중 트러블슈팅 공유] webpack, webpack-cli 버전
1
144
1
질문 an error occurred while loading the image
1
468
1
webpack에서 babel-loader 사용할때 질문
1
149
1
자주 사용하는 플러그인 에서 질문이 있습니다.
1
167
1
eslint no-extra-semi 관련 질문
1
142
1
webpack5 에서 open index.html하는법 + 질문
1
166
1
혹시 웹팩 5 내용으로 강의 업데이트는 안되는건가요?
1
370
1
에러없이 png안뜨시는 분들
1
273
1
Error: Cannot find module 'node:crypto'
1
463
1
DefinePlugin 관련; env와 관련하여, (21.06.22 16:15, aloha_jh) 답변포함
1
404
1
깃허브 확인 문의
0
574
1
폴더를 prettier로 돌렸을 때 나오는 에러 구문에 대한 질문
0
404
1
해쉬값과 캐쉬 갱신
1
458
1
Hash 에러 발생
1
2664
2
webpack.config.js에서의 CommonJS방식에 대한 질문
0
828
3
웹팩 버전
0
521
1
웹팩-cli 버전을 명시하지 않으면 왜 에러가 날까요?
0
482
1
import해오는 두가지 방법에 대해 제가 잘 이해한건지 확인받고 싶습니다!!
0
318
1





