【发布时间】:2020-05-18 12:27:28
【问题描述】:
我有 NestJs API 服务,当它使用“npm run dev”命令运行时,它运行得非常好。但是当我 dockerized 时,它无法运行该应用程序。我也使用容器尝试了节点版本 9,10 和 12。但它使用 run dev 命令在我的计算机中使用节点版本 9 顺利运行。
我正在使用docker run -it -p 9000:3001 dev-service 来运行容器。错误如下。
nestjs-sample-api@1.0.0 start /app
> node index.js "prod"
TypeError: Cannot read property 'constructor' of undefined
at Object.<anonymous> (/app/node_modules/cli-highlight/src/theme.ts:4:26)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Object.require.extensions.(anonymous function) [as .js] (/app/node_modules/ts-node/src/index.ts:406:14)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Module.require (internal/modules/cjs/loader.js:598:17)
at require (internal/modules/cjs/helpers.js:11:18)
at Object.<anonymous> (/app/node_modules/cli-highlight/src/index.ts:3:1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nestjs-sample-api@1.0.0 start: `node index.js "prod"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nestjs-sample-api@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-05-15T03_20_53_617Z-debug.log
Docker 文件:
ROM node:9
WORKDIR /app
COPY package.json /app
COPY ormconfig.json /app
RUN npm install
COPY . /app
COPY ormconfig.json /dist/
CMD ["npm", "start", "prod" ]
【问题讨论】:
-
似乎这是由于容器中的 npm 缓存损坏所致。检查这是否有帮助:stackoverflow.com/questions/42308879/npm-err-code-elifecycle
标签: docker devops nestjs docker-container