执行ng new my-app时uws@9.14.0包安装失败求助
Hey there, let's work through this uws installation error you're facing while running ng new my-app on your AWS EC2 Linux instance. The root issues here usually boil down to missing system-level build dependencies for node-gyp or compatibility mismatches between your older Node.js version (9.9.0) and the uws@9.14.0 package. Here are step-by-step fixes to resolve this:
1. Install Required System Build Dependencies
node-gyp (the tool compiling uws's native code) needs specific tools to run. AWS EC2's default Linux images often don't include these out of the box.
- For Amazon Linux 2/RHEL/CentOS:
sudo yum install gcc-c++ make python2 -y - For Ubuntu/Debian:
sudo apt-get update && sudo apt-get install build-essential python2 -y
Note: uws@9.14.0 relies on Python 2, so make sure you don't use Python 3 here.
2. Clean npm Cache and Reinstall Dependencies
Corrupted cache or partial installs can also trigger this error. Let's reset your project's dependencies:
- Clean the npm cache:
npm cache clean --force - Delete the existing
node_modulesfolder and lock file:rm -rf node_modules package-lock.json - Re-run the install command:
npm install
3. Workaround: Skip Native Module Compilation (Temporary)
If the above steps don't work, you can temporarily bypass the node-gyp rebuild for uws:
npm install --ignore-scripts
Warning: This skips all script runs for packages, so only use this if you're sure other dependencies don't need native compilation.
4. Upgrade Node.js (Long-Term Solution)
Node.js 9.x is no longer supported (reached end-of-life years ago), which is a major source of compatibility issues with older packages like uws@9.14.0. Upgrading to an LTS version (like 14.x, which is still supported) will resolve most such problems:
- Install nvm (Node Version Manager) to manage Node versions easily:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash - Source your shell profile to activate nvm:
source ~/.bashrc - Install and use Node.js 14 LTS:
nvm install 14 nvm use 14 - Now re-run your Angular project creation command:
ng new my-app
Once you've tried these steps, the uws installation should complete without errors. If you still run into issues, double-check that your EC2 instance has internet access to download all required packages.
内容的提问来源于stack exchange,提问作者MILJO JOHN

