npm 安装挂起,没有错误
通过 Elastic Beanstalk 预置的 AWS/EC2 实例上的 npm 存在一些问题
此外,相同的安装在非 aws ubuntu 和 macos 上运行良好
如果我尝试安装一些较小的软件包,如 lodash、mongoose 等。它工作正常,但是当尝试安装 Express 或其他较大的软件包时,它会挂起
机器类型: t2.large 和 t2.medium(运行 amazon linux)
尝试过的版本: #1 节点 18.20.4/npm 10.7.1 #2 节点 20.18.0/npm 10.8.2
uname -r: 6.1.115-126.197.amzn2023.x86_64
磁盘:8GB - 大量可用磁盘空间 [ec2-user@ip-172-31-46-96 ~]$ df -h 已使用的文件系统大小 可用 使用% 安装于 devtmpfs 4.0M 0 4.0M 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 1.6G 17M 1.6G 2% /运行 /dev/xvda1 8.0G 5.5G 2.5G 70% / tmpfs 3.9G 20M 3.9G 1% /tmp
这是 npm install 挂起时顶部输出的样子 - 所以,内存并不短缺
top - 22:36:46 up 26 min, 3 users, load average: 3.87, 2.80, 1.68
Tasks: 126 total, 1 running, 125 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.2 us, 0.0 sy, 0.0 ni, 94.3 id, 0.0 wa, 0.0 hi, 0.0 si, 5.5 st
MiB Mem : 7930.2 total, 3466.0 free, 1015.9 used, 3448.3 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 6585.0 avail Mem
dmesg 显示了很多这样的消息
[ 1349.092480] INFO: task iou-sqp-3249:3260 blocked for more than 1105 seconds.
[ 1349.093925] Not tainted 6.1.115-126.197.amzn2023.x86_64 #1
[ 1349.095186] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[ 1349.097048] task:iou-sqp-3249 state:D stack:0 pid:3260 ppid:3247 flags:0x00004000
[ 1349.098968] Call Trace:
[ 1349.099781] <TASK>
[ 1349.100549] __schedule+0x1ad/0x530
[ 1349.101497] ? _raw_spin_unlock+0xa/0x30
[ 1349.102529] schedule+0x5a/0xd0
[ 1349.103434] schedule_preempt_disabled+0x11/0x20
[ 1349.104520] __mutex_lock.constprop.0+0x372/0x6c0
[ 1349.105634] ? io_submit_sqes+0x303/0x390
[ 1349.106644] io_sq_thread+0x275/0x4e0
[ 1349.107616] ? membarrier_register_private_expedited+0x90/0x90
[ 1349.108860] ? io_sqd_handle_event+0xd0/0xd0
[ 1349.109904] ret_from_fork+0x22/0x30
[ 1349.110863] </TASK>
这是 npm 运行日志中的最后一段条目
600 http fetch GET 200 https://registry.npmjs.org/binary-extensions 3ms (cache hit)
5601 silly packumentCache full:https://registry.npmjs.org/binary-extensions set size:49673 disposed:false
5602 silly placeDep node_modules/ts-node-dev [email protected] OK for: [email protected] want: ^2.0.0
5603 silly placeDep node_modules/ts-node-dev [email protected] OK for: [email protected] want: ^0.6.0
5604 silly placeDep node_modules/unset-value [email protected] OK for: [email protected] want: ^0.1.4
5605 silly placeDep node_modules/unset-value/node_modules/has-value [email protected] OK for: [email protected] want: ^2.0.0
5606 silly placeDep node_modules/wrap-ansi [email protected] OK for: [email protected] want: ^5.0.1
5607 silly placeDep node_modules/readdirp/node_modules/expand-brackets [email protected] OK for: [email protected] want: ^0.1.0
5608 silly reify moves {}
发生这种情况是由于亚马逊 Linux 内核 6.1.115-126.197.amzn2023.x86_64 中的一个错误,默认情况下为 Linux 2023 上的 NodeJS 20 环境提供,
通过替换 config.yml 中的这一行来切换到不同的内核来修复问题
default_platform:在 64 位 Amazon Linux 2023 上运行的 Node.js 20
与
default_platform:在 64 位 Amazon Linux 2 上运行的 Node.js 18