Can't run npm install on new docker container - node.js

I've been stuck for a couple of days trying to get a docker container to run for npm on my laravel install. No matter what I try npm install always ends in the error below or something similar.
npm ERR! code EINTEGRITY
npm ERR! sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA== integrity checksum failed when using sha512: wanted sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA== but got sha512-XfyffAC+g/7ZA4f5L0XtDj2yuUZIpXolG23LrI8FAM9661vPwCRW50r9xTi16O7+IhE+OGMFJrOLnBvSbByphQ==.
I have tried npm cache verify, npm cache clear --force, removing package-lock.json, and reinstalling npm within the container.
My dockerfile is
FROM node:latest
WORKDIR /var/www
COPY package*.json ./
RUN npm cache verify
RUN node -v (node -v returns 14.2.0)
RUN npm -v (npm -v returns 6.14.4)
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
and in my docker-compose
npm:
image: node:latest
container_name: npm
working_dir: /var/www
build:
context: ./
dockerfile: node.dockerfile
My package.json is the default from the laravel install (below)
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.19",
"bootstrap": "^4.0.0",
"cross-env": "^7.0",
"jquery": "^3.2",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"resolve-url-loader": "^2.3.1",
"sass": "^1.20.1",
"sass-loader": "^8.0.0",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
}
}
Any help at this point would be very much appreciated. Thank you.

Related

npm install --production ignore my dependencies

I have this package.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"dependencies": {
"cross-env": "^7.0.3"
},
"devDependencies": {
"autoprefixer": "^10.2.6",
"axios": "^0.19",
"browser-sync": "^2.26.14",
"browser-sync-webpack-plugin": "^2.3.0",
"cross-env": "^7.0.3",
"laravel-mix": "^6.0.19",
"less": "^3.13.1",
"less-loader": "^7.3.0",
"lodash": "^4.17.21",
"resolve-url-loader": "^3.1.3",
"vue-template-compiler": "^2.6.14"
}
}
Just for testing how do work NodeJS, NPM, Laravel and Laravel Mix (Webpack) together, I run:
npm install --production (https://docs.npmjs.com/cli/v7/commands/npm-install)
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.
Actual behavior
When I go to node_modules folder, I don't see any cross-env package there. Moreover the output of the command line is:
$ npm install --production
up to date, audited 1 package in 17s
found 0 vulnerabilities
, meaning no package (in particular: cross-env) was installed.
Expected behavior
cross-env (and only cross-env) would be installed, being part of dependencies, with this command: npm run install --production.
Question
Why does dependencies array seem to be ignored by NPM?
You have cross-env also listed in devDependencies. Dependencies should only be declared in one location. Perhaps npm ignored cross-env as it is listed in devDependencies.
I have found that this occurs even if the dependency is not explicitly listed twice in package.json but is a sub-dependency of a package declared in dependencies. My example:
{
"dependencies": {
"sharp": "^0.26.1" // depends on "color" which depends on "color-convert"
},
"devDependencies": {
"color-convert": "^2.0.1"
}
}
In this example, color-convert will NOT be installed if running npm install --only=production even though it is a dependency of a production dependency (using npm v6.14.14)

While "$ npm run watch" is running, if a file in a directory is modified, then run a custom script

I have the following dummy Laravel 5.5 + React project:
$ git clone https://github.com/tlg-265/laravel-5.5-react.com
$ cd laravel-5.5-react.com
$ npm i
$ npm run watch
My goal is: while: $ npm run watch is running, whenever some of the files: /template/template-XX.json is modified, the script /template/listener.js be executed.
When that happens, the variable: template (inside: listener.js) should get the name of that modified file (JSON file above), for example: template-02.json.
Here is the content of file /template/listener.js:
var template = '###TBD###';
console.log(`The template: ${template} was modified.`);
Probably one way to achieve that is to configure the file: package.json accordingly. This is the content of file: package.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.17",
"babel-preset-react": "^6.23.0",
"bootstrap-sass": "^3.3.7",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^1.0",
"less": "^3.11.1",
"less-loader": "^5.0.0",
"lodash": "^4.17.4",
"react": "^15.4.2",
"react-dom": "^15.4.2"
}
}
Just in case, this is a preview of the file structure:
Any idea on how to achieve that?
Thanks!

Fresh Laravel Homestead 8.0.1: npm run dev fails to compile and npm ci fails to install. Something with cross-env?

I recently upgraded my Homestead from 6.3 to fresh Laravel Homestead 8.1.
I ssh'ed into the VM as usual to compile assets in my Laravel project via npm run dev and it started failing.
I was getting issue that Node Sass does not yet support your current environment (similar to this) but running:
sudo npm rebuild node-sass and npm uninstall --save node-sass and npm install --save node-sass didn't help.
When I completely remove node_modules via rm -rf node_modules or do npm ci it install stuff and fails at the end with:
No idea how to fix this. My node and npm versions are below:
node -v gives v12.7.0
npm -v gives 6.10.2
package.json is:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"test": "cross-env NODE_ENV=test jest",
"tdd": "npm run test -- --watch --notify"
},
"devDependencies": {
"#coreui/coreui": "^2.0.4",
"#fortawesome/fontawesome-svg-core": "^1.2.2",
"#fortawesome/free-brands-svg-icons": "^5.2.0",
"#fortawesome/free-regular-svg-icons": "^5.2.0",
"#fortawesome/free-solid-svg-icons": "^5.2.0",
"#vue/test-utils": "^1.0.0-beta.10",
"axios": "^0.18",
"babel-jest": "^22.1.0",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"jest": "^22.1.4",
"jest-vue-preprocessor": "^1.3.1",
"jquery": "^3.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.5",
"pace": "github:HubSpot/pace#v1.0.2",
"perfect-scrollbar": "^1.4.0",
"popper.js": "^1.12.4",
"sweetalert2": "^7.0.7",
"vue": "^2.5.7"
},
"jest": {
"testURL": "http://localhost",
"roots": [
"<rootDir>/tests/Javascript/"
],
"moduleNameMapper": {
"^vue$": "vue/dist/vue.common.js"
},
"moduleFileExtensions": [
"js",
"vue"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/jest-vue-preprocessor"
}
},
"dependencies": {
"bootstrap-datepicker": "^1.8.0",
"clipboard": "^2.0.4",
"datatables.net": "^1.10.19",
"datatables.net-bs4": "^1.10.19",
"datatables.net-scroller": "^2.0.0",
"debounce": "^1.2.0",
"jquery-datatables-checkboxes": "^1.2.11",
"owl.carousel": "^2.3.4",
"select2": "^4.0.6-rc.1"
}
}
Can somebody give me any hint? I'm happy to provide additional output from any logs if needed. I'm blocked by this one.
Full reset did the job:
rm -rf node_modules
rm package-lock.json
npm cache clear --force
npm install
then
npm run dev
I committed new package-lock.json into the repository. Can somebody at least explain what was the culprit?

npm doesn't install packages that listed in package.json file with Laravel/Homestead

I have an issue with "npm install" on my Laravel Homestead, and the problem is that npm doesn't install packages listed in package.json file like laravel-mix... etc.
I have installed last version of nodejs and npm on my homestead machine. This is my package.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.18",
"bootstrap": "^4.0.0",
"popper.js": "^1.12",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.4",
"vue": "^2.5.7"
}
}
It's not a direct answer to your question, but I think you should be running npm install on your host machine, and not in the vagrant box.
The end result of running scripts defined in package.json is the compilation of js/css which will be consumed by the browser anyway - there should be no difference where you run them.
I was confused by this for a long time, and finally realized it makes no sense for Laravel projects to try and run npm scripts in Homestead. I posted a question about it here back in January, and started running npm scripts exclusively on host since then. And magically, almost all of my npm-related problems disappeared (this applies to both Windows 10, and Ubuntu 16.04 hosts).
As an added bonus, the scripts should execute faster from your host, since your skipping the unnecessary 'Vagrant layer'.

npm install error in laravel 5.6 with fresh installation

I get the following error while running npm install on a fresh laravel 5.6 installation on windows 7 32 bit, npm version 5.7.1, node v9.5.0
npm ERR! path
D:\xampp\htdocs\2018\thehealthsearch\node_modules\node-sass\node_modules\har-validator\bin\har-validator
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod 'D:\xampp\htdocs\2018\thehealthsearch\node_modules\node-sass\no
de_modules\har-validator\bin\har-validator'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2018-03-14T05_58_42_171Z-debug.log
How to resolve this?
EDIT :
My Package.json file
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.18",
"bootstrap": "^4.0.0",
"popper.js": "^1.12",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.4",
"vue": "^2.5.16"
},
"dependencies": {
"har-validator": "^5.1.0",
"yarn": "^0.16.1"
}
}
You need to try this commands line by line:
npm cache clean
npm install -g gulp bower
npm install
bower install
gulp & gulp watch
This commands do:
for cleaning a cache of npm
installs gulp bower globally
installs npm
installs bower
for mixing all js and css and watch on all changes of css & js
Hope this will helps you and fixed your issue!

Resources