I am trying to use docker in order to run npm & bower install.
Here is my configuration:
./package.json
{
"name": "bignibou-client",
"version": "0.1.0",
"engines": {
"node": "0.10.x"
},
"devDependencies": {
"bower": "1.3.12",
"grunt": "~0.4.5",
"grunt-contrib-uglify": "~0.6.0",
"grunt-contrib-concat": "~0.5.0",
"karma": "~0.12.23",
"grunt-karma": "~0.9.0",
"karma-junit-reporter": "~0.2.2",
"karma-jasmine": "~0.1.5",
"karma-phantomjs-launcher": "~0.1.4",
"phantomjs": "~1.9.11",
"grunt-mkdir": "~0.1.2",
"grunt-contrib-cssmin": "~0.10.0",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-copy": "~0.7.0",
"karma-htmlfile-reporter": "~0.1.2",
"grunt-filerev": "~2.1.2",
"grunt-usemin": "~2.6.2",
"grunt-protractor-runner": "~1.1.4",
"protractor": "~1.4.0",
"flow": "~0.2.3",
"assemble-less": "~0.7.0"
},
"scripts": {
"postinstall": "node_modules/bower/bin/bower install"
}
}
.bowerrc
{
"json": "bower.json", "directory": "bignibou-client/src/bower_components"
}
My command:
docker run --privileged=true -it --rm \
-w /usr/src/app \
-v $(pwd)/package.json:/usr/src/app/package.json \
-v $(pwd)/.bowerrc:/usr/src/app/.bowerrc \
-v $(pwd)/./bower.json:/usr/src/app/bower.json \
-v ./build/npm.tmp/node_modules:/usr/src/app/node_modules \
-v ./build/npm.tmp/bignibou-client/src/bower_components:/usr/src/app/bignibou-client/src/bower_components \
digitallyseamless/nodejs-bower-grunt npm install
I just get the following console output:
npm WARN package.json bignibou-client#0.1.0 No description
npm WARN package.json bignibou-client#0.1.0 No repository field.
npm WARN package.json bignibou-client#0.1.0 No README data
npm WARN package.json bignibou-client#0.1.0 No license field.
and nothing is generated on the host...
Can someone please provide advice as to how to get it working or an alternative solution?
edit:
Running the following command:
docker run --privileged=true -it --rm \
-w /usr/src/app \
-v $(pwd):/usr/src/app \
digitallyseamless/nodejs-bower-grunt npm install
results in:
npm WARN package.json bignibou-client#0.1.0 No repository field.
npm WARN package.json bignibou-client#0.1.0 No license field.
npm WARN cannot run in wd bignibou-client#0.1.0 node_modules/bower/bin/bower install (wd=/usr/src/app)
-v $(pwd)/package.json:/usr/src/app/package.json
this flag will create a package.json directory but not the file.
Here is how your command should look like:
docker run --privileged=true -it --rm \
-w /usr/src/app \
-v $(pwd):/usr/src/app\
digitallyseamless/nodejs-bower-grunt bash -c "npm install && bower --allow-root install"
And after this script create node_modules and bower_components in current directory on HOST mashine and you can manipulate with result as you wish.
Related
This is my package.json after uninstalling sass node-sass and sass-loader because I changed my node version from 14 to 16,
{
"name": "our-awesome-project",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"static": "NUXTJS_DEPLOY_TARGET=static NUXTJS_SSR=true nuxt generate",
"build-and-start": "NUXTJS_DEPLOY_TARGET=server NUXTJS_SSR=false nuxt build && NUXTJS_DEPLOY_TARGET=server NUXTJS_SSR=false nuxt start"
},
"husky": {
"hooks": {
"pre-commit": "cross-env PRE_COMMIT=true lint-staged -r"
}
},
"dependencies": {
"core-js": "^3.19.3",
"nuxt": "^2.15.8",
"nuxt-i18n": "^6.28.1",
"nuxt-purgecss": "^1.0.0",
"vue": "^2.6.14",
"vue-server-renderer": "^2.6.14",
"vue-template-compiler": "^2.6.14",
"webpack": "^4.46"
},
"devDependencies": {
"#nuxtjs/eslint-config": "^8.0.0",
"#nuxtjs/google-fonts": "^1.3.0",
"#nuxtjs/storybook": "^4.2.0",
"#nuxtjs/style-resources": "^1.2.1",
"#vue/cli-plugin-babel": "^4.5.15",
"babel-eslint": "^10.1.0",
"eslint": "^8.7.0",
"husky": "^7.0.4",
"nuxt-svg-loader": "^1.2.0",
"postcss": "^8.4.5"
}
}
According to this I should install node-sass version 6.0
But I'm trying:
npm install --save-dev sass#1.49.0 node-sass#6.0.1 sass-loader#10.2.1
Also, read here to add --unsafe-perm so I tried:
npm install --save-dev --unsafe-perm sass#1.49.0 node-sass#6.0.1 sass-loader#10.2.1
But it keeps failing, being the first error always this one:
npm ERR! code 1
npm ERR! path /Users/toniweb/Proyectos/our-awesome-project/node_modules/node-sass
npm ERR! command failed
npm ERR! command sh -c node scripts/build.js
npm ERR! Building: /Users/user/.nvm/versions/node/v16.13.1/bin/node /Users/toniweb/Proyectos/our-awesome-project/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
I tried removing node_modules package-lock.json and the same result
Of course, this is driving me nuts.. please tell me that anyone has an idea to try out
I think you are using ARM64 which is not supported by node-sass.
You should replace node-sass with sass(Dart Sass) as LibSass is deprecated
Just replace node-sass in your package.json file with sass. Both packages expose the same JavaScript API.
npm uninstall node-sass
npm install --save-dev sass
We have a Nuxt 2.15.8 app running on Node 16, in which a couple of months ago we switched from node-sass to sass, as the former is deprecated.
I recall at the time it took some figuring out, but in the end we just needed to install some postcss parsers to get the Nuxt app fully working with sass & sass-loader.
Taking as the baseline the package.json in your post, try:
npm install --save-dev \
sass#1.49.4 \
sass-loader#10.2.1 \
postcss-html#1.3.0 \
postcss-scss#4.0.3
The error message hints to node-gyp as the culprit. To work on a MacOS, node-gyp requires the XCode Command Line Tools to be installed (see here). So basically, in case you haven't done that yet, run
xcode-select --install
Or try any of the other methods described here. Then retry to install node-sass.
in fact , I think you have pasted the wrong error infomation.
there are two ways may help you
npm i --force this command will ignored the error in the package.json
use the pnpm , you can install it by
npm i -g pnpm
# then
pnpm i
I've been trying to debug this super weird issue. Got a project where I am trying to install a private repository with the npm command.
This does not work when it's in an existing project but does when it's a newly created project that's just been created with npm init.
The existing project is in /app and the new project is in /opt (for testing purposes)
Running npm add git+ssh://git#github.com:company/repository.git in /app returns with:
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git#github.com/company/repository.git
npm ERR! git#github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-11-24T00_25_10_559Z-debug.log
Running the exact same command from the /opt project installs the package correctly without any issues.
I'm running this from an alpine docker box with openssh installed.
This is the Dockerfile
FROM node:16.13-alpine
RUN apk add --no-cache openssh-client git python2
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts && ln -s /run/secrets/ssh_key ~/.ssh/id_rsa && ln -s /run/secrets/ssh_pub_key ~/.ssh/id_rsa.pub
RUN mkdir /app
WORKDIR /app
A few more informative stuff
/app # node -v
v16.13.0
/app # npm -v
8.1.4
/app # ssh -T git#github.com
Hi AzaZPPL! You've successfully authenticated, but GitHub does not provide shell access.
package.json
{
"name": "project",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"generate-schema": "node apollo/generate-schema.js",
"lint": "eslint --ext .js,.vue --ignore-path .eslintignore .",
"lintfix": "eslint --fix --ext .js,.vue --ignore-path .eslintignore ."
},
"dependencies": {
"#nuxtjs/apollo": "^4.0.1-rc.4",
"#nuxtjs/auth": "^4.9.1",
"#nuxtjs/axios": "^5.12.2",
"#nuxtjs/dayjs": "^1.2.1",
"#nuxtjs/style-resources": "^1.0.0",
"apollo-cache-inmemory": "^1.6.6",
"copy-to-clipboard": "^3.3.1",
"core-js": "^3.6.5",
"date-fns": "^2.19.0",
"dotenv": "^8.2.0",
"filepond": "^4.27.1",
"filepond-plugin-file-validate-type": "^1.2.6",
"filepond-plugin-image-preview": "^4.6.6",
"graphql-tag": "^2.11.0",
"js-file-download": "^0.4.12",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.20",
"nuxt": "^2.14.6",
"nuxt-buefy": "^0.4.10",
"nuxt-i18n": "^6.15.4",
"vee-validate": "^3.4.3",
"vue": "^2.6.12",
"vue-filepond": "^6.0.3"
},
"devDependencies": {
"#babel/eslint-parser": "^7.16.3",
"eslint": "^7.12.1",
"eslint-config-prettier": "^6.15.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-vue": "^7.1.0",
"prettier": "^2.1.2",
"sass": "^1.32.8",
"sass-loader": "^12.3.0"
}
}
Any ideas in what is going on here?
Try in your Dockerfile to set
ENV GIT_SSH_COMMAND='ssh -Tv'
That should give you more clues as to why your SSH key is or is not considered during npm add.
With the help of #VonC's answer I was able to figure out what was going on.
Taking a closer look at the logs, I found out that there is actually a user called node which is used when running npm. Inside the Dockerfile of the Alpine image this user was being created and npm is configured to use this user.
So what happened was whenever I logged into the docker container I was logging in as the root user and all the ssh keys which were set in the Dockerfile were being run by the root user.
Running the ssh -T git#github.com worked because the root user was setup correctly but not the node user
What I still can't get my head around is why did running the command in the /opt folder work? Anyway that's a mystery for a different day.
This is my updated Dockerfile. I set the ssh keys to the node user and login as the node user
FROM node:16.13-alpine
RUN apk add --no-cache openssh-client git
RUN mkdir /app && chown node:node /app
USER node
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN ln -s /run/secrets/ssh_key ~/.ssh/id_rsa
WORKDIR /app
I'm trying to make a build a Docker image of a react application.
Here is the first part of the package.json:
{
"name": "front",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^11.2.7",
"#testing-library/user-event": "^12.8.3",
"eslint": "^7.29.0",
"html-react-parser": "^1.2.7",
"npm": "^6.14.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-input-mask": "^3.0.0-alpha.2",
"react-redux": "^7.2.4",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.3",
"redux": "^4.1.0",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^2.0.3",
"web-vitals": "^1.1.2"
},
Here is the Dockerfile:
# pull official base image
FROM node:13.12.0-alpine
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
ARG REACT_APP_BASEURL='https://localhost:8081'
ENV REACT_APP_BASEURL=$REACT_APP_BASEURL
# install app dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm install
# add app
COPY . ./
#EXPOSE
EXPOSE 3000
# start app
CMD ["npm", "start"]
So, I build with the command line:
docker build -f Dockerfile -t api_front .
and I've this error message:
npm WARN read-shrinkwrap This version of npm is compatible with
lockfileVersion#1, but package-lock.json was generated for
lockfileVersion#2. I'll try to do my best with it!
If I check the version of npm with npm -v , I've the latest one (7.19.1)
If I go to the project folder and I run npm install , everything is up-to-date
If I start the application with npm start , everything is ok and the api is running...
What is the problem?
Edit: SOLUTION
I've changed:
FROM node:13.12.0-alpine
to
FROM node:latest
The version of npm (v7.19.1) used to generate the package-lock.json file is newer than the version of npm (v6.14.4) inside the docker image of node 13.12.0.
1: The lockfile version used by npm v5 and v6.
2: The lockfile version used by npm v7, which is backwards compatible to v1 lockfiles.
You can read more about lockfile versions here
You can either upgrade the docker image to use the lastest version or downgrade your npm to generate a compatible package-lock.json
EDIT #1:
You have to replace the first line of your docker file with:
FROM node:16.4.2
I was able to install all packages with npm, but two days ago I'm getting this error.
Step 8/12 : RUN npm install
---> Running in aedc04c5281e
> sharp#0.25.4 install /home/project/website/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)
info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.9.1/libvips-8.9.1-linuxmusl-x64.tar.gz
> cwebp-bin#5.1.0 postinstall /home/project/website/node_modules/cwebp-bin
> node lib/install.js
⚠ spawn /home/project/website/node_modules/cwebp-bin/vendor/cwebp ENOENT
⚠ cwebp pre-build test failed
ℹ compiling from source
...
Here is my docker file
FROM node:12-alpine
RUN apk add --no-cache build-base gcc autoconf automake libtool zlib-dev libpng-dev nasm
RUN mkdir -p /home/project/website/node_modules && chown -R node:node /home/project/website
WORKDIR /home/project/website
COPY /package*.json ./
USER node
RUN npm cache verify
RUN npm install
COPY --chown=node:node . .
RUN chmod +x wait-for.sh
RUN chmod -R 0755 /home/project/website/src/views/
EXPOSE 8080
after the building completed I get this in logs
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module '/home/project/website/node_modules/.bin/nodemon'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
and after I run this following cmd
docker-compose run website sh -c "npm list --depth=0"
I get this
+-- UNMET DEPENDENCY bcryptjs#2.4.3
+-- UNMET DEPENDENCY compression#1.7.4
| +-- accepts#1.3.7
| +-- bytes#3.0.0
| +-- compressible#2.0.18
| +-- debug#2.6.9
| +-- on-headers#1.0.2
| +-- safe-buffer#5.1.2
| `-- vary#1.1.2
+-- UNMET DEPENDENCY cors#2.8.5
| +-- object-assign#4.1.1
| `-- vary#1.1.2
+-- UNMET DEPENDENCY dateformat#3.0.3
+-- UNMET DEPENDENCY dotenv#8.2.0
+-- UNMET DEPENDENCY ejs#3.1.5
| `-- jake#10.8.2
+-- UNMET DEPENDENCY express#4.17.1
...
and my packages are
{
"name": "website",
"version": "0.0.0",
"main": "app.js",
"scripts": {
"start": "nodemon src/app.js"
},
"author": "Noah Lc",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dateformat": "^3.0.3",
"dotenv": "^8.2.0",
"ejs": "^3.1.3",
"express": "^4.17.1",
"fs": "0.0.1-security",
"helmet": "^4.1.1",
"image-size": "^0.8.3",
"imagemin": "^7.0.1",
"imagemin-mozjpeg": "^9.0.0",
"imagemin-webp": "^6.0.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.7.7",
"multer": "^1.4.2",
"nodemailer": "^6.4.11",
"nodemon": "^2.0.3",
"sharp": "^0.25.4",
"sitemap": "^6.2.0",
"slugify": "^1.4.0",
"superagent": "^5.2.2",
"validator": "^12.0.0",
"winston": "^3.3.3"
},
"devDependencies": {}
}
Are there any clean ways to skip pre and post-build steps of those dips in the plugin itself to avoid any issues in the containerized environment?
RUN apk add --no-cache \
--update \
build-base \
mesa-dev \
gcc \
autoconf \
automake \
libtool \
zlib-dev \
nasm \
mesa \
libxi \
libpng-dev \
libjpeg \
jpeg-dev
I'm trying to install npm packages for my application within a Dockerfile. However, I get the following error when it comes to installing a package from a private git repository.
Step 9/10 : RUN npm ci
---> Running in 57960fe4df81
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ***github.com/<redacted-private-org>/<redacted-private-repo>.git
npm ERR!
npm ERR! remote: Repository not found.
npm ERR! fatal: repository 'https://github.com/<redacted-private-org>/<redacted-private-repo>.git/' not found
npm ERR!
npm ERR! exited with error code: 128
Dockerfile
FROM node:12.18.0-alpine3.10
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh
RUN mkdir -p /home/dev
WORKDIR /home/dev
COPY . /home/dev
RUN npm ci
CMD ["node", "api/api.js"]
package.json
{
"name": "api",
"version": "0.1.0",
"author": "me",
"license": "",
"scripts": {
"prestart": "",
"start": "NODE_ENV=development nodemon ./api/server.js",
},
"dependencies": {
"bcrypt-nodejs": "^0.0.3",
"body-parser": "^1.18.2",
"org-common-utils": "git+https://<redacted-username>:<redacted-token>#github.com/<redacted-private-org>/<redacted-private-repo>.git",
"cors": "^2.8.4",
"dotenv": "^8.2.0",
"express": "^4.16.3",
"express-routes-mapper": "^1.1.0",
"helmet": "^3.12.0",
"igdb-api-node": "^3.1.7",
"jsonwebtoken": "^8.2.1",
"mysql": "^2.16.0",
"mysql2": "^1.6.4",
"node-cache": "^4.2.0",
"sequelize": "^5.21.3",
"sqlite3": "^4.0.0",
},
"devDependencies": {
"cross-env": "^5.1.4",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.18.0",
"husky": "^0.14.3",
"jest": "^22.4.3",
"nodemon": "^1.17.3",
"shx": "^0.2.2",
"supertest": "^3.0.0"
}
}
To install from a private Github repository I'm using a username and token combination as you can see in my package.json.
The repository exists because if I try to navigate to the URL it loads when I'm logged in
https://github.com/redacted-private-org/redacted-private-repo
This issue is only occurring in github actions pipeline.
This issue was only occurring in github actions pipeline. It's solved by setting persist-credentials to false otherwise it uses github actions token which does not have the necessary permissions to pull/install the repository.
.
- name: Checkout
uses: actions/checkout#master
with:
persist-credentials: false
https://github.com/actions/checkout