为了在让 react 应用进行服务端渲染。使用了 NextJs。安装 webpack 依赖时,出现下面错误:

错误信息

更多错误日志信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
npm ERR! Linux 3.10.0-123.9.3.el7.x86_64
npm ERR! argv "/usr/local/node-v6.10.0-linux-x64/bin/node" "/usr/local/node-v6.10.0-linux-x64/bin/npm" "install" "webpack" "-S"
npm ERR! node v6.10.0
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE

npm ERR! uglifyjs-webpack-plugin@0.4.6 postinstall: `node lib/post_install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the uglifyjs-webpack-plugin@0.4.6 postinstall script 'node lib/post_install.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the uglifyjs-webpack-plugin package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node lib/post_install.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs uglifyjs-webpack-plugin
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls uglifyjs-webpack-plugin
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /home/baoxuebin/demo/npm-debug.log

服务器环境版本信息:

1
2
3
Linux: CentOS 7.0
Node: v6.10.0
NPM: 3.10.3

google 搜索一番后,发现有人在 webpackissue 提过相关问题。

https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/129

然而我并没有看懂怎么解决。我的理解是:uglifyjs-webpack-plugin@0.4.6 还未安装或安装失败(或许是网络原因),安装脚本却执行了这个依赖里面的 post_install.js

最后的解决方法是:在服务器上安装了 yarn,yarn add webpack

关于 yarn 的安装,可以参考官网,还可以选择中文 😃
https://yarnpkg.com/zh-Hans/docs/install