3

I have the following Dockerfile:

FROM node:latest
WORKDIR /usr/src/app

ENV NODE_ENV=production

COPY package*.json .
    
RUN npm install && npm i -g typescript

COPY . .

RUN  tsc

CMD [ "node", "./dist/index.js" ]

And the following package.json:

  "dependencies": {
    "discord.js": "^12.5.3",
    "moment": "^2.29.1"
  },
  "devDependencies": {
    "@types/node": "^14.14.37",
    "typescript": "^4.2.4"
  }

When I try to build the image, I get the following error:

Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`

Does anyone know why that happens? I have @types/node installed.

4
  • seems like we need more info. you can add index.js/ts maybe? Commented Apr 11, 2021 at 18:59
  • @srknzl well the only thing thats from importance in index.ts is const API_KEY = process.env.API_KEY;. Otherwise, it's a standard discord bot. Also a note - it compiles perfectly fine when using tsc on my system AND on an unrelated fresh install of Ubuntu 18.04. Commented Apr 11, 2021 at 19:01
  • 2
    devDependencies won't be installed for production mode Commented Apr 11, 2021 at 19:37
  • @ExplodingKitten thanks that was it. totally forgot about that. would you mind writing that as an answer, so I can accept it? Commented Apr 12, 2021 at 13:13

1 Answer 1

8

devDependencies won't be installed for production mode.

So, you can:

  • Move these packages to dependencies or
  • Remove NODE_ENV environment variable or
  • Use multi-stage build, where you will build TypeScript on the first stage (keep dependencies as is, but you don't need production here), and use JS files on the second stage (you don't need devDependencies here, so, production will work).
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.