0

I have NestJs API service and it's run very well when it runs using "npm run dev" command. but when I dockerized, it failed to run the app. I tried node versions 9,10 and 12 also with the container. but it runs smoothly with node version 9 in my computer using run dev command. I'm using docker run -it -p 9000:3001 dev-service to run container. the error is below.

 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 File:

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" ]
Dasun_96
  • 173
  • 1
  • 7
  • Seems this is due to corrupt npm cache in the container. Check if this helps: https://stackoverflow.com/questions/42308879/npm-err-code-elifecycle – Kashinath Patekar May 15 '20 at 04:22

1 Answers1

1

I fixed that issue by install chalk library. It happens due to the contractor is finding for chalk and it doesn't install in node modules. but this caused only when I run through the docker. Anyway, it's worked after I put chalk into the dependencies.

Dasun_96
  • 173
  • 1
  • 7