OpenShift pod 中的'npm ERR! could not determine executable to run'



我正在尝试部署一个Angular应用程序到OpenShift,下面是我的package.json的副本

{
"name": "app-admin",
"version": "0.1.0",
"scripts": {
"global": "npm install",
"start": "npx ng serve",
"build": "npx ng build",
"watch": "npx ng build --watch --configuration development",
"test": "npx ng test",
"e2e": "npx ng e2e",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
"private": true,
"dependencies": {
"@angular/animations": "^14.2.0",
"@angular/common": "^14.2.0",
"@angular/compiler": "^14.2.0",
"@angular/core": "^14.2.0",
"@angular/forms": "^14.2.0",
"@angular/platform-browser": "^14.2.0",
"@angular/platform-browser-dynamic": "^14.2.0",
"@angular/router": "^14.2.0",
"drag-on-drop": "^3.6.1",
"npm": "^9.2.0",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^14.2.6",
"@angular/cli": "~14.2.6",
"@angular/compiler-cli": "^14.2.0",
"@cypress/schematic": "^2.2.0",
"@types/jasmine": "~4.0.0",
"axe-core": "^4.4.3",
"cypress": "^10.10.0",
"cypress-axe": "^1.0.0",
"jasmine-core": "~4.3.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "~4.7.2"
},
"overrides": {  
"loader-utils@>2.0.0 <3": "2.0.4",
"loader-utils@>3.0.0 <4": "3.2.1"
}
}

pod在npx ng serve失败,出现以下错误

ERROR: ld.so: object 'libnss_wrapper.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object 'libnss_wrapper.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object 'libnss_wrapper.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
npm info using npm@9.2.0
npm info using node@v18.9.1
npm http fetch GET 200 https://registry.npmjs.org/npm 828ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/npm 881ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/ng 1096ms (cache miss)
npm ERR! could not determine executable to run

我已经尝试了这个链接中的每个答案,并阅读了这个reddit帖子。来自其他stackoverflow帖子的解决方案在调试pod中工作,但当我在scripts中添加步骤时。在下次构建中,pods再次出现相同的错误。

我尝试添加到scripts的东西:

"install": "npm install -g npm@9.2.0"
"prestart": "npm install -g"

还尝试将npm版本放在dependencies中,并使用engines指定npm版本。

任何帮助都是感激的。

您可能没有将glibcnss_wrapper-libs包放入容器中。有些npm模块需要它在安装过程中执行编译(比如couchbase模块)。

您可以尝试使用多阶段构建dockerfile,并且只在构建器映像中使用glibc,而不是最终映像。

在我的例子中,出现这个问题是因为没有安装package.json中的devdependencies。我必须通过一个环境变量NODE_DEV=development来安装它们,这解决了我的问题。感谢这篇文章。

对于将来遇到同样问题的读者:如果我的解决方案不适合你,请检查其他答案是否对你的情况有帮助。

相关内容

最新更新