'dist' folder is not generated while doing npm build in a Dockerfile
Asked Answered
C

4

9

I usually write Dockerfiles for Java / Go applications and it's the first time I have encountered a situation where I have to write a Dockerfile for an already existing (and production running) Node.js application. As per my little knowledge about the Node.js which I acquired in the past couple of days, dist folder is generated after we build a Node.js project which carries the source code (please correct me if I am wrong here). So I am interested in copying the dist folder from parent Docker image to child Docker image.

However, after I copy everything from an application into my parent Docker image (line 6) and run 'npm run build' command, dist folder is not generated for me (please note the node_modules and package-lock.json are being generated).

My Dockerfile is as below:

FROM node:10-alpine as BUILD
WORKDIR /src
COPY package*.json /src
RUN apk add --update --no cache \
    python \
    make \
    g++
RUN npm install
COPY . /src
RUN npm run build

How can I resolve this?

Creaky answered 11/1, 2020 at 11:33 Comment(4)
Does it work outside of Docker? What do or don't you see? What does the "build" command do inside your package.json file?Chirr
@DavidMaze - Hi, I just tried locally building the project and I am surprised to see that even when I locally build it, dist folder is not getting generated. Not sure what would be the reason behind this (please note that node_modules and package-lock,json is generated). Also, I didn't get any error post build and Compiled Successfully message was shown. Coming to your 2nd point - build command inside package.json is written as - "build" = "next build". Please let me know if you need any additional informationCreaky
You may find the following reading interesting: #37976000Dinh
@Dinh - I went through the article and modified Dockerfile to include below 2 commands - RUN npm install -g grunt-cli RUN npm install grunt just before the line COPY . /src. Still I am not able to see dist folder generated in my docker imageCreaky
I
12

If you are using typescript in your node application then follow these instructions.

Please add the below entry under compilerOptions section on "tsconfig.json"

tsconfig.json

**"outDir": "./dist/"**

package.json - Add the below script too.

"scripts": { "build": "tsc" }

Now, re-run the "npm run build". You will see the dist folder.

Intuitivism answered 15/4, 2020 at 0:51 Comment(1)
do you mean "outDir": "./dist/" and not **"outDir": "./dist/"**.Lineate
S
1

Try by ignoring the 'tsconfig.tsbuildinfo' file. don't copy this file into docker container.

Spectacles answered 1/2, 2021 at 18:39 Comment(0)
D
0

Anyone using nestjs, Oddly in my Dockerfile I had RUN npm run build and was not pulling any folders/files besides tsconfig.build.tsbuildinfo, once I made it RUN npx nest build it copied all of the files over.

Dole answered 2/6, 2023 at 18:46 Comment(0)
K
0

you can add in pipeline

  • task: Npm@1 inputs: command: 'custom' customCommand: 'run-script build:azure' displayName: 'Run NPM Build Script'

it will create the dist folder check the root folders inside the pipeline

Kweiyang answered 25/7 at 10:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.