Этап npm install в моем приложении начал давать сбой из-за ошибки нехватки памяти, когда после обновления зависимостей, узла и npm нет package-lock.json. Неудачные версии:
node v18.19.1
npm 10.5.0
работает на Ubuntu 23.10 с 8 ГБ памяти.
npm install успешен, когда package-lock.json присутствует; однако без файла кажется, что этап разрешения в последней версии занимает больше памяти, чем в предыдущих версиях.
$ npm install
npm WARN using --force Recommended protections disabled.
(⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠧ idealTree:@angular/core: sill placeDep ROOT [email protected] OK for: [email protected] want: ^0.14.4
<--- Last few GCs --->
[6093:0x6643c70] 32888 ms: Scavenge 1987.5 (2035.9) -> 1985.7 (2035.4) MB, 7.8 / 0.0 ms (average mu = 0.704, current mu = 0.714) task;
[6093:0x6643c70] 33552 ms: Mark-sweep (reduce) 2064.0 (2110.8) -> 2058.5 (2095.6) MB, 455.9 / 0.1 ms (+ 101.8 ms in 28 steps since start of marking, biggest step 8.6 ms, walltime since start of marking 575 ms) (average mu = 0.500, current mu = 0.301)
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 0xb95be0 node::Abort() [npm install]
2: 0xa9a7f8 [npm install]
3: 0xd6f5b0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [npm install]
4: 0xd6f957 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [npm install]
5: 0xf4ceb5 [npm install]
6: 0xf5f38d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [npm install]
7: 0xf39a7e v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [npm install]
8: 0xf3ae47 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [npm install]
9: 0xf1b3c0 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [npm install]
10: 0xf12e34 v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawWithImmortalMap(int, v8::internal::AllocationType, v8::internal::Map, v8::internal::AllocationAlignment) [npm install]
11: 0xf150e8 v8::internal::FactoryBase<v8::internal::Factory>::NewRawOneByteString(int, v8::internal::AllocationType) [npm install]
12: 0x1055349 v8::internal::JsonParser<unsigned short>::MakeString(v8::internal::JsonString const&, v8::internal::Handle<v8::internal::String>) [npm install]
13: 0x1057066 v8::internal::JsonParser<unsigned short>::ParseJsonValue() [npm install]
14: 0x1057b4f v8::internal::JsonParser<unsigned short>::ParseJson() [npm install]
15: 0xdf5213 v8::internal::Builtin_JsonParse(int, unsigned long*, v8::internal::Isolate*) [npm install]
16: 0x170e179 [npm install]
Aborted (core dumped)
Вы можете воспроизвести с помощью следующего:
{
"name": "npm-oom",
"version": "0.0.1",
"dependencies": {
"@angular/animations": "^16.2.12",
"@angular/cdk": "^16.2.14",
"@angular/cli": "^16.2.12",
"@angular/common": "^16.2.12",
"@angular/compiler": "^16.2.12",
"@angular/compiler-cli": "^16.2.12",
"@angular/core": "^16.2.12",
"@angular/forms": "^16.2.12",
"@angular/language-service": "^16.2.12",
"@angular/material": "^16.2.14",
"@angular/platform-browser": "^16.2.12",
"@angular/platform-browser-dynamic": "^16.2.12",
"@angular/router": "^16.2.12",
"@sendgrid/mail": "^8.1.1",
"@stomp/stompjs": "^7.0.0",
"@types/file-saver-es": "^2.0.3",
"cross-var": "^1.1.0",
"enhanced-resolve": "^5.15.1",
"file-saver-es": "^2.0.5",
"jwt-decode": "^4.0.0",
"ng-storages": "^1.1.5",
"npm": "^10.5.0",
"reflect-metadata": "^0.2.1",
"reinstall": "^2.0.0",
"rxjs": "^7.4.0",
"tslib": "^2.0.0",
"typescript": "^5.1.6",
"zone.js": "^0.14.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.2.12",
"@angular-eslint/builder": "^16.3.1",
"@angular-eslint/eslint-plugin": "^16.3.1",
"@angular-eslint/eslint-plugin-template": "^16.3.1",
"@angular-eslint/schematics": "^16.3.1",
"@angular-eslint/template-parser": "^16.3.1",
"@types/jasmine": "^5.1.4",
"@types/node": "^20",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"jasmine-core": "^5.1.2",
"jasmine-spec-reporter": "^7.0.0",
"karma": "^6.3.14",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^3.0.2",
"karma-jasmine": "^5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"protractor": "^7.0.0",
"ts-node": "^10.0.0",
"webdriver-manager": "^12.1.9"
}
}
и
npm install -g [email protected]; rm -rf node_modules/ package-lock.json; npm install --force





Похоже, это регрессия в алгоритме разрешения зависимостей npm cli; Я открыл ошибку с помощью npm:
https://github.com/npm/cli/issues/7276
Это можно обойти, расширив память по умолчанию:
node --max-old-space-size=8000 $(which npm) install
или перейти на npm 10.3.0 или более раннюю версию; эта проблема впервые появилась в npm 10.4.0, а также присутствует в (текущей последней) npm 10.5.0.