Docker Node Sass does not yet support your current environment - node.js

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

Related

Testing local npm package using Docker

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 ?

failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 1

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

npm WARN old lockfile The package-lock.json file was created with an old version of npm

I've a dockerfile as below, but during RUN npm ci step, there is a warning,
npm WARN old lockfile The package-lock.json file was created with an old version of npm
which I can not able to figure out..
I tried with npm install rather npm ci and added the --package-lock flag, but I am still getting this warning. It’s a kind of warning that I have to ignore it or what should I do to solve this?
Step 12/26 : RUN npm ci --production --package-lock && npm ci --production --package-lock --prefix ./ui-runner
---> Running in 3473c209b98c
npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
Here is my Dockerfile.
FROM node:14.17.1-alpine3.13 AS builder
WORKDIR /usr/src/app
COPY package.json package-lock.json* ./
COPY ui-runner/package*.json ./ui-runner/
COPY .npmrc .npmrc
COPY ui-runner/.npmrc ./ui-runner/.npmrc
RUN npm -g install npm#7.19.1
RUN npm ci --production --package-lock && \
npm ci --production --package-lock --prefix ./ui-runner
RUN rm -f .npmrc && \
rm -f ui-runner/.npmrc
FROM node:14.17.1-alpine3.13
WORKDIR /usr/src/app
RUN apk update && apk add --no-cache curl bash
RUN addgroup -g 1001 test && \
adduser -S -u 1001 -G test test
RUN chown -R test /usr/src/app && \
chmod 755 /usr/src/app
COPY --from=builder /usr/src/app /usr/src/app
COPY . .
RUN npm run build:docker
USER test
EXPOSE 3000 9183
CMD [ "npm", "run", "start:ui-runner" ]
There are several ways to deal with this:
Ignore it. It's just a warning and does not affect the installation of modules.
Run npm install --package-lock-only (with the newer version of npm) to regenerate a package-lock.json. Commit the updated version of package-lock.json to the repo/Docker image or whatever.
Downgrade npm to an older version in production. Consider running npm version 6 as that is what ships with the current (as of this writing) Long Term Support (LTS) version of Node.js. In the case being asked about in this question, I imagine you can just leave out the RUN npm -g install npm#7.19.1 from the Dockerfile and instead use the version of npm that is installed with the Docker image (which in this case will almost certainly be npm#6 since that is what ships with Node.js 14.x).
If you already have a version of npm installed but want to run one command with an older version of npm but otherwise keep the newer version, you can use npx (which ships with npm) to do that. For example, npx npm#6 ci would run npm ci with npm version 6 even if you have version 7 installed.
I had a similar problem but upgrading npm npm i -g npm on my machine before building the image solved it for me. You may still get the warn message but the image build process won't be halted.
An easy solution to this is to use NVM to manage your node versions. Especially on Linux this saves a lot of trouble with file permissions, developing in different environments, etc. NPM recommends this in their documentation here.
This error for me was solved by switching Node.js versions with nvm,
nvm install 14
nvm use 14
It is always an easy thing to try and switch to a slightly older or newer Node.js version if you are running into weird Node.js or npm issues.
I am having the same problem as well after upgrading my npm version. It seems like a bug from npm 7.19.1, and I'd suggest to downgrade to an older version.
You can check below for all the npm versions
https://www.npmjs.com/package/npm?activeTab=versions
Install the desired version with this command in the console, and substitute "V" with your desired version:
npm install -g npm#"V"
TL;DR
As Trott suggested it is totally fine to ignore the warning. To fix the warning/problem keep reading.
The problem/warning is with the line:
RUN npm -g install npm#7.19.1
Removing this line should fix the problem/warning.
Explanation
The package-lock generated which is part of your source repository ideally is generated with npm version < npm#7 which ships with Node.js <= node#14.x.x. My guess comes from your first line of Dockerfile.
FROM node:14.17.1-alpine3.13 AS builder
For example Node.js LTS v14.17.1 ships with npm#6.14.13. See the full release list here.
npm#5, npm#6 generate package-lock#v1, which is now a legacy release as per this link. And npm#7 which is the latest release generates package-lock#v2. When you do: npm -g install npm#7.19.1. It overrides your existing package-lock#v1 with package-lock#v2 giving out the warning in the process.`
npm WARN old lockfile The package-lock.json file was created with an old version of npm`
The updated Dockerfile should look like this:
FROM node:14.17.1-alpine3.13 AS builder
WORKDIR /usr/src/app
COPY package.json package-lock.json* ./
COPY ui-runner/package*.json ./ui-runner/
COPY .npmrc .npmrc
COPY ui-runner/.npmrc ./ui-runner/.npmrc
RUN npm ci --production --package-lock && \
npm ci --production --package-lock --prefix ./ui-runner
RUN rm -f .npmrc && \
rm -f ui-runner/.npmrc
FROM node:14.17.1-alpine3.13
WORKDIR /usr/src/app
RUN apk update && apk add --no-cache curl bash
RUN addgroup -g 1001 test && \
adduser -S -u 1001 -G test test
RUN chown -R test /usr/src/app && \
chmod 755 /usr/src/app
COPY --from=builder /usr/src/app /usr/src/app
COPY . .
RUN npm run build:docker
USER test
EXPOSE 3000 9183
CMD [ "npm", "run", "start:ui-runner" ]
I was facing a similar issue. After reading the previous comments, I noticed that the Node.js version installed on my machine was v14.17.5 and the npm version was v7.19.1. Referring to version history lookup and downgrading npm to v6.14.14 (compatible against node v14.17.5) resolved issue.
First check for your Node.js version: Go to a cmd prompt and
node -v
Based on the version, check the node-sass version and install it:
npm node-sass#version
From node-sass:
Node 16 - 6.0+
Node 15 - 5.0+
Node 14 - 4.14+
Node 13 - 4.13+,
Node 12 - 4.12+
Node 11 - 4.10+,
Node 10 - 4.9+,
Node 8 - 4.5.3+,
Node <8 - <5.0
I had similar problem with Strapi v4
I used:
1)
nvm use 16.15.1
(old was 14.X.X)
2)
npm rebuild
npm install
Seem to work now.

Docker node Error: 'darwin-x64' binaries cannot be used on the 'linux-x64' platform

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?

Error while building vue/quasar app on Docker

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.

Resources