webpack 运行 npm 安装时的不同错误
webpack running with different errors on npm install
当我 运行 npm install
或 npm ci
似乎触发了一个产生大量不正确错误的 webpack 构建。所有这些都指的是肯定存在的未找到的依赖项。此外,npm ci
似乎比 npm install
触发的错误更多。
当我 运行 构建 webpack 时,构建 运行 没问题。
我对这种行为感到非常惊讶,因为我似乎没有找到任何关于触发此 webpack 的内容的文档 运行.
我想进一步了解:
- 什么在
npm install
期间触发了 webpack? (我非常喜欢安装依赖项)
- 为什么会显示所有这些奇怪的错误消息?
我已经安装了:
- WSL 2 (Ubuntu 21.04) Windows 11
- NPM 7.5.2
- Webpack ^5.65.0
示例错误输出如下所示:
matthias@daiquiri:~/dev/hamster-books$ npm ci
asset main.js 42.9 KiB [emitted] (name: main)
asset index.html 2.91 KiB [emitted]
cached modules 3.96 KiB [cached] 4 modules
code generated modules 9.58 KiB [code generated]
modules by path ./app/js/ui/ 6.5 KiB
modules by path ./app/js/ui/*.js 1.45 KiB
./app/js/ui/loadingDialog.js 177 bytes [code generated]
./app/js/ui/ui.js 1.27 KiB [code generated]
modules by path ./app/js/ui/_impl/*.js 5.05 KiB
./app/js/ui/_impl/createElement.js 480 bytes [code generated]
./app/js/ui/_impl/uiElementFactory.js 4.59 KiB [code generated]
modules by path ./app/js/*.js 3.08 KiB
./app/js/hamstersBooks.js 629 bytes [code generated]
./app/js/dispatcher.js 2.47 KiB [code generated]
./node_modules/xdate/src/xdate.js 19.5 KiB [built]
LOG from webpack.FileSystemInfo
<w> Managed item /home/matthias/dev/hamster-books/node_modules/html-webpack-plugin isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
<w> Managed item /home/matthias/dev/hamster-books/node_modules/style-loader isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
<w> Managed item /home/matthias/dev/hamster-books/node_modules/css-loader isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
<w> Managed item /home/matthias/dev/hamster-books/node_modules/less-loader isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
<w> Managed item /home/matthias/dev/hamster-books/node_modules/xdate isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
<w> Managed item /home/matthias/dev/hamster-books/node_modules/ts-loader isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
+ 19 hidden lines
ERROR in ./app/js/dispatcher.js 2:32-75
Module not found: Error: Can't resolve 'ts-loader' in '/home/matthias/dev/hamster-books'
@ ./app/js/hamstersBooks.js 1:17-40
ERROR in ./app/js/dispatcher.js 3:40-69
Module not found: Error: Can't resolve 'ts-loader' in '/home/matthias/dev/hamster-books'
@ ./app/js/hamstersBooks.js 1:17-40
ERROR in ./app/js/dispatcher.js 4:34-81
Module not found: Error: Can't resolve 'ts-loader' in '/home/matthias/dev/hamster-books'
@ ./app/js/hamstersBooks.js 1:17-40
此后输出持续了一段时间,它也在重复,试图 运行 webpack 几个 times.I 也检查了 - 所有这些被引用的目录和文件都存在。事实证明其中一些来自 node_modules
而其他一些只是常规项目引用
擦除 node_modules
并重新安装。这样做的原因基本上就是@Harshal Patil 评论的全部内容,即包触发其 install/postinstall 脚本后发生冲突。
(这是我在评论中提出的建议,解决了问题,现在作为答案,以便对其他有类似问题的人有所帮助)
当我 运行 npm install
或 npm ci
似乎触发了一个产生大量不正确错误的 webpack 构建。所有这些都指的是肯定存在的未找到的依赖项。此外,npm ci
似乎比 npm install
触发的错误更多。
当我 运行 构建 webpack 时,构建 运行 没问题。 我对这种行为感到非常惊讶,因为我似乎没有找到任何关于触发此 webpack 的内容的文档 运行.
我想进一步了解:
- 什么在
npm install
期间触发了 webpack? (我非常喜欢安装依赖项) - 为什么会显示所有这些奇怪的错误消息?
我已经安装了:
- WSL 2 (Ubuntu 21.04) Windows 11
- NPM 7.5.2
- Webpack ^5.65.0
示例错误输出如下所示:
matthias@daiquiri:~/dev/hamster-books$ npm ci
asset main.js 42.9 KiB [emitted] (name: main)
asset index.html 2.91 KiB [emitted]
cached modules 3.96 KiB [cached] 4 modules
code generated modules 9.58 KiB [code generated]
modules by path ./app/js/ui/ 6.5 KiB
modules by path ./app/js/ui/*.js 1.45 KiB
./app/js/ui/loadingDialog.js 177 bytes [code generated]
./app/js/ui/ui.js 1.27 KiB [code generated]
modules by path ./app/js/ui/_impl/*.js 5.05 KiB
./app/js/ui/_impl/createElement.js 480 bytes [code generated]
./app/js/ui/_impl/uiElementFactory.js 4.59 KiB [code generated]
modules by path ./app/js/*.js 3.08 KiB
./app/js/hamstersBooks.js 629 bytes [code generated]
./app/js/dispatcher.js 2.47 KiB [code generated]
./node_modules/xdate/src/xdate.js 19.5 KiB [built]
LOG from webpack.FileSystemInfo
<w> Managed item /home/matthias/dev/hamster-books/node_modules/html-webpack-plugin isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
<w> Managed item /home/matthias/dev/hamster-books/node_modules/style-loader isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
<w> Managed item /home/matthias/dev/hamster-books/node_modules/css-loader isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
<w> Managed item /home/matthias/dev/hamster-books/node_modules/less-loader isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
<w> Managed item /home/matthias/dev/hamster-books/node_modules/xdate isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
<w> Managed item /home/matthias/dev/hamster-books/node_modules/ts-loader isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
+ 19 hidden lines
ERROR in ./app/js/dispatcher.js 2:32-75
Module not found: Error: Can't resolve 'ts-loader' in '/home/matthias/dev/hamster-books'
@ ./app/js/hamstersBooks.js 1:17-40
ERROR in ./app/js/dispatcher.js 3:40-69
Module not found: Error: Can't resolve 'ts-loader' in '/home/matthias/dev/hamster-books'
@ ./app/js/hamstersBooks.js 1:17-40
ERROR in ./app/js/dispatcher.js 4:34-81
Module not found: Error: Can't resolve 'ts-loader' in '/home/matthias/dev/hamster-books'
@ ./app/js/hamstersBooks.js 1:17-40
此后输出持续了一段时间,它也在重复,试图 运行 webpack 几个 times.I 也检查了 - 所有这些被引用的目录和文件都存在。事实证明其中一些来自 node_modules
而其他一些只是常规项目引用
擦除 node_modules
并重新安装。这样做的原因基本上就是@Harshal Patil 评论的全部内容,即包触发其 install/postinstall 脚本后发生冲突。
(这是我在评论中提出的建议,解决了问题,现在作为答案,以便对其他有类似问题的人有所帮助)