Docker run for NestjS Microservice failing with error TS2307

468 Views Asked by At

I have hit an issue while building a docker image for a NestJS microservice.

When I run npm start locally, this is response I see:

11:16:05 am - Starting compilation in watch mode...
11:16:12 am - Found 0 errors. Watching for file changes.
[Nest] 32132   - 16/02/2022, 11:16:15 am   [NestFactory] Starting Nest application...     
[Nest] 32132   - 16/02/2022, 11:16:16 am   [InstanceLoader] ConfigHostModule dependencies 
initialized +363ms
[Nest] 32132   - 16/02/2022, 11:16:16 am   [InstanceLoader] AppModule dependencies initialized +2ms
[Nest] 32132   - 16/02/2022, 11:16:16 am   [InstanceLoader] ConfigModule dependencies initialized +1ms
[Nest] 32132   - 16/02/2022, 11:16:17 am   [InstanceLoader] DatabaseModule dependencies initialized +1655ms
[Nest] 32132   - 16/02/2022, 11:16:17 am   [NestMicroservice] Nest microservice successfully started +15ms

However when I run the docker image, this is the response I get:

5:41:10 AM - Starting compilation in watch mode...
node_modules/sequelize-typescript/dist/hooks/shared/hook-meta.d.ts(2,32): error TS2307: Cannot find module 'sequelize/types/lib/hooks' or its corresponding type declarations.
node_modules/sequelize-typescript/dist/hooks/shared/hooks-service.d.ts(4,32): error TS2307: Cannot find module 'sequelize/types/lib/hooks' or its corresponding type declarations.
5:41:34 AM - Found 2 errors. Watching for file changes.

My Docker file looks like this. I am pre-building the application with npm start and copying over all folders to a content-service folder created in docker root. I have excluded the node_modules and package-lock.json through .dockerignore

FROM node:14.16-alpine
WORKDIR /content-service
COPY . . 
RUN npm install
RUN npm i @nestjs/cli
RUN npm install --save sequelize-cli
RUN npm i -g pm2
EXPOSE 3002
CMD ["npm","start"]

This is how my local directory looks. I can see the hooks.d.ts file here under sequelize/types/lib Local directory screenshot

But when I look inside the container running this image, I dont see this folder. The hook.d.ts file is placed directly inside of sequelize/types instead of sequelize/types/lib:

Container sreenshot

When I directly update the hooks-service.d.ts and hook-meta.d.ts files inside the container to point towards sequelize/types instead of sequelize/types/lib, the application starts.

6:09:20 AM - Found 0 errors. Watching for file changes.
[Nest] 446   - 02/16/2022, 6:09:27 AM   [NestFactory] Starting Nest application...

Any pointers on how I can build it without this would be greatly appreciated.

My local machine versions:

  • Angular CLI: 13.1.2 Node: 16.13.1 Package Manager: npm 6.14.7 OS: win32 x64

Edit: Resolved thanks to a suggestion from @DavidMaze. I was ignoring package-lock.json. Copying 'Package-lock.json' into the image fixed this issue for me!

Please check comments on this answer for the solution.

0

There are 0 best solutions below