문제상황
typescript와 webpack을 같이 사용하려고 했다. webpack
, webpack-cli
, webpack-dev-server
를 devDependencies로 깔고 typescrip
t는 global로 깔았다. 근데 build해보니까 아래와 같은 에러가 났다.
./src/main.ts 1.01 KiB [built] [code generated]
1 ERROR in child compilations
webpack 5.4.0 compiled with 1 error in 1919 ms
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tetris@1.0.0 build: `webpack`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tetris@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\W41413-0\AppData\Roaming\npm-cache\_logs\2020-11-14T10_41_44_077Z-debug.log
해결방안 찾기
재건설
여기에 나온대로 cache를 지우고, node_modules
폴더와 package-lock.json
파일을 삭제해봤다.
npm cache clean --force && rd /s /q node_modules && del /f package-lock.json
하지만 그래도 똑같은 에러가 났다.
webpack을 잘못쓴듯
./node_modules/.bin/webpack
이 코드를 써서 build를 했는데, 그냥 cmd에 webpack
이라고 하니까 다른 에러가 나왔다. 다시말해서,,,처음에 만난 에러는 /node_modules/.bin/webpack
이거를 써서 그런거였다. 이제 남은 에러는
1 ERROR in child compilations
이 에러는 내가 webpack.config.js
파일을 잘못 작성해서 발생한거였다.
plugins: [
new MiniCssExtractPlugin({
filename: "style.css",
}),
new HtmlWebpackPlugin({
template: join(__dirname, '/src/index.html')
})
],
HtmlWebpackPlugin
에서 html template의 위치를 /src/index.html
로 설정했는데 src
에는 index.html
이 없었다. 그래서 이거를 수정해 주니까 webpack이 잘 빌드해주었다.
