Docker error on npm run build ( vue-cli-service build )
I'm working on containerizing an app for use it on a cloud service with kubernetes. But in the build stage of my Dockerfile I'm getting an error wuth the vue-cli-plugin-quasar.
Maybe it's something with the quasar package and the access of external packages in the docker building process, but I'm a noob on docker.
I tried to use RUN npm i -g #vue/cli before the manage of the packages(npm i, audit etc).
And found nothing while searching about this problem.
Tried with multi-stage Dockerfile
FROM node:12 as dev-stage
WORKDIR /my-app
COPY package*.json ./
COPY server/ ./server
COPY src/ ./src
RUN npm install -g #vue/cli
RUN npm i
RUN npm audit fix
RUN cd server && npm i
RUN cd server && npm audit fix
FROM dev-stage as build-stage
RUN npm run build
I have more stages after this, but the error occurs in the build
And without it
FROM node:12 as dev-stage
WORKDIR /my-app
COPY package*.json ./
COPY server/ ./server
COPY src/ ./src
RUN npm install -g #vue/cli
RUN npm i
RUN npm audit fix
RUN cd server && npm i
RUN cd server && npm audit fix
RUN npm run build
Error output
ERROR TypeError: Cannot read property 'quasar' of undefined
TypeError: Cannot read property 'quasar' of undefined
at module.exports (/my-app/node_modules/vue-cli-plugin-quasar/index.js:2:29)
at /my-app/node_modules/#vue/cli-service/lib/Service.js:83:7
at Array.forEach (<anonymous>)
at Service.init (/my-app/node_modules/#vue/cli-service/lib/Service.js:81:18)
at Service.run (/my-app/node_modules/#vue/cli-service/lib/Service.js:221:10)
at Object.<anonymous> (/my-app/node_modules/#vue/cli-service/bin/vue-cli-service.js:37:9)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
Obs: I listed my node_modules folder after the npm i and the quasar package is there
I could overcome this issue with a multistage build as follows:
FROM node:12.14.1-alpine3.11 as get-sources
RUN apk add --no-cache bash && \
apk update && \
apk upgrade && \
apk add git && \
apk add openssh-client
.....
RUN git clone ssh://git#private-repo.com/user/Project.git
FROM node:12.14.1-alpine3.11 as build-stage
RUN apk update && apk add python make g++ && \
npm config --global set python2 /usr/bin/python
WORKDIR /app
# copy the repository form the previous stage
COPY --from=get-sources /Project/src ./
# get dependencies
RUN yarn install --production
COPY ./ .
RUN yarn build
......
# copy dist to final production stage
Basically instead of copying only the package.json and and install/build the app based only on that i copied the whole source of the app , and build the app in that context. Then in the next stage you copy only the /dist content in the final location.
Related
I have a local npm package which I need to build and run npm link inside Docker container. I have these line in my Dockerfile
WORKDIR /usr/src/app
COPY . .
RUN npm ci && npm run build && npm link
How can I test this npm package outside of Docker container ?
I'm really new to Docker and would like to create a container that has all my angular website and its dependencies in it. I read some data and how-to's to do it but I keep struggling.
Here is my Dockerfile:
FROM node:latest AS build
WORKDIR /usr/src/app
COPY package.json ./
COPY package-lock.json ./
RUN npm cache clean --force
RUN rm -rf node_modules && rm ./package-lock.json
# RUN npm install -g npm#8.5.2
RUN npm install
COPY . .
RUN npm install -g #angular/cli
RUN chown -R $USER /usr/local/lib/node_modules
RUN npm run build
### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /usr/src/app/dist/demo2 /usr/share/nginx/html
EXPOSE 80
FROM node:latest as nodeBuilder
RUN npm rebuild node-sass
WORKDIR /var/www/app
COPY ./webapp /var/www/app
RUN npm install
RUN npm run build
RUN rm -rf node_module
when i run this got this error
Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (88)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.14.1
i use
FROM node:12.22.1 as nodeBuilder
WORKDIR /var/www/app
COPY ./backend /var/www/app
RUN rm -rf node_module
RUN npm install
RUN npm rebuild node-sass
RUN npm run build
RUN rm -rf node_module
and it's work because of node v15 dose not support node_sass
I am trying to run a container based on my app image by using docker and i getting the next error:
/app/node_modules/sharp/lib/libvips.js:68
throw new Error('${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the '${currentPlatformId}' platform.);
Error: 'darwin-x64' binaries cannot be used on the 'linux-x64' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'linux-x64' platform.
My Dockerfile:
FROM node:10.20.1
WORKDIR /app
COPY package.json .
RUN npm install -g node-gyp
RUN npm install
EXPOSE 8080
CMD [ "npm", "start" ]
I tryied to add the next Commands to my Dockerfile but i am getting the same error:
Second attempt Dockerfile:
FROM node:10.20.1
WORKDIR /app
COPY package.json .
RUN npm install -g node-gyp
RUN rm -rf node_modules/sharp
RUN npm install --arch=x64 --platform=linux --target=8.10.0 sharp
EXPOSE 8080
CMD [ "npm", "start" ]
The docker command I using locally on my mac in order to run that container is:
docker run -d -p 8080:8080 --env-file ./.env --name server-dev-1 server:1
Any ideas?
I'm trying to run a fresh installation of React using a Dockerfile.
FROM node:12.14-alpine
RUN mkdir /app
WORKDIR /app
RUN npm install -g nodemon \
npx create-react-app .
COPY package.json package.json
RUN npm install --silent
COPY . .
CMD [ "node", "start" ]
My root folder is empty so no package.json file exists etc. When I run docker-compose up --build I get the following error which indicates that's failing on npx create-react-app .
Step 5/9 : RUN npm install -g nodemon npx create-react-app .
---> Running in c4878af5f94d
npm ERR! code ENOLOCAL
npm ERR! Could not install from "" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-02-18T12_55_14_899Z-debug.log
ERROR: Service 'react' failed to build: The command '/bin/sh -c npm install -g nodemon npx create-react-app .' returned a non-zero code: 1
Any ideas what I'm doing wrong? I'm not having node or npm installed nativelly so all needs t run through docker
You need to delete the . at the end of the RUN :
RUN npm install -g nodemon \
npx \
create-react-app
You forgot "&&" at the beginning line 7
FROM node:12.14-alpine
RUN mkdir /app
WORKDIR /app
RUN npm install -g nodemon \
&& npx create-react-app .
COPY package.json package.json
RUN npm install --silent
...
CMD [ "node", "start" ]