Docker npm install fails - node.js

I'm trying to build an ASP.Net 5.0 web app using Docker, but it fails when it reaches the npm install step, with:
Step 14 : RUN npm install
---> Running in 15c191d1ca1d
npm WARN deprecated gulp-karma#0.0.4: Please use Karma directly: https://github.com/karma-runner/gulp-karma
npm WARN deprecated graceful-fs#3.0.8: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs#^4.0.0 as soon as possible.
npm WARN deprecated lodash#1.0.2: lodash#<3.0.0 is no longer maintained. Upgrade to lodash#^4.0.0.
npm WARN deprecated graceful-fs#1.2.3: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs#^4.0.0 as soon as possible.
npm WARN deprecated graceful-fs#2.0.3: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs#^4.0.0 as soon as possible.
npm WARN deprecated npmconf#2.1.2: this package has been reintegrated into npm and is now out of date with respect to npm
npm WARN prefer global typescript#1.5.3 should be installed with -g
npm WARN prefer global node-gyp#3.3.1 should be installed with -g
> node-sass#3.4.2 install /app/src/CDWebDesigner/node_modules/node-sass
> node scripts/install.js
Binary downloaded and installed at /app/src/CDWebDesigner/node_modules/node-sass/vendor/linux-x64-11/binding.node
> spawn-sync#1.0.15 postinstall /app/src/CDWebDesigner/node_modules/spawn-sync
> node postinstall
Installing native dependencies (this may take up to a minute)
> node-sass#3.4.2 postinstall /app/src/CDWebDesigner/node_modules/node-sass
> node scripts/build.js
The command 'npm install' returned a non-zero code: 1
ERROR: Build failed with: exit status 1
I can't see any errors here that explain why it's failing, only WARNings. I assume this must either be a problem with the npm installation or the modules it's trying to install. loadash#1.0.2 says it will fail on newer npm installs, but I don't know how to update this, or which of the dependencies is pulling this in.
Dockerfile
FROM microsoft/aspnet:1.0.0-rc1-final
RUN apt-get update && apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup | bash -
RUN apt-get install -y nodejs
RUN apt-get install bzip2
RUN curl -L https://npmjs.org/install.sh | sh
# Install bower
RUN npm install -g bower
# Install Gulp
RUN npm install -g gulp
# Install Git (for bower)
RUN apt-get -y install git
COPY . /app
WORKDIR /app
RUN ["dnu", "restore"]
WORKDIR ./src/myapp
RUN ["npm", "install"]
RUN ["bower", "install", "--allow-root"]
RUN ["gulp", "prod"]
EXPOSE 5000
CMD dnx kestrel
package.json
{
"name": "ASP.NET",
"version": "0.0.0",
"devDependencies": {
"gulp": "3.8.11",
"gulp-concat": "2.5.2",
"gulp-cssmin": "0.1.7",
"gulp-uglify": "1.2.0",
"del": "^2.2.0",
"gulp-sass": "^2.0.4",
"gulp-typescript": "~2.8.0",
"main-bower-files": "~2.9.0",
"gulp-sourcemaps": "~1.5.2",
"mocha": "~2.2.5",
"gulp-mocha": "~2.1.3",
"karma-chai": "~0.1.0",
"chai": "~3.2.0",
"karma": "~0.13.9",
"karma-jasmine": "~0.3.6",
"karma-phantomjs-launcher": "~0.2.1",
"karma-spec-reporter": "~0.0.20",
"gulp-karma": "^0.0.4",
"gulp-js-obfuscator": "~1.0.0",
"gulp-order": "^1.1.1",
"gulp-debug": "^2.1.2"
}
}

Not sure, but 1st: you can try install with sudo npm install, and 2nd you can try to install on this machine node-gyp and pyton 2.7 . If module during installation require compilation of node extension, then you will need these two things.
3rd. How we usually debug: Create an image on the state before failing command. run container with interactive shell (with -it). login inside. And run npm install by hands. See and understand output there. Fix.

Related

Error when trying to install react-redux dependency

I am getting an error trying to install the react-redux package onto my create-react-app application. I have tried deleting and reinstalling my node_modules folder as well as installing it with admin permissions and I am still receiving the same error
➜ frontend git:(main) ✗ npm i react-redux
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
Here is the remaining output from the console
npm ERR!
npm ERR! While resolving: frontend#0.1.0
npm ERR! Found: react#17.0.1
npm ERR! node_modules/react
npm ERR! react#"^17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^16.8.3" from react-redux#7.2.1
npm ERR! node_modules/react-redux
npm ERR! react-redux#"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
Here is the list of current dependencies in my package.json
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"axios": "^0.21.0",
"react": "^17.0.1",
"react-bootstrap": "^1.4.0",
"react-dom": "^17.0.1",
"react-router-bootstrap": "^0.25.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.4",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"tachyons": "^4.12.0"
},
It looks like you are using the latest npm version (v7).
As mention in the logs, try with
npm install --legacy-peer-deps
The last time npm Blog mentioned the --legacy-peer-deps flag was while their beta version of npm v7 got public. To read more about the flag go here.
Two ways:
npm install <package-name> --legacy-peer-deps
install Recommended node version for most users
The better way is to install the recommended version of node to work for all packages.
Try installing recommended nodejs version(screen shot below). Which should fix this issue.
Here is a recreation of this error and its solution (screenshots below):
Problem:
Nodejs : Latest features:
Solution:
Nodejs : Recommended for most users:
Installing the Recommended version of node js fixed this issue instantly allowing installation of relevant dependancies.
Incase you are facing this issue with a react-native dependency then once you have installed the recommended version be sure to update your pod file.
Try using Node.js latest "Recommended For Most Users" Version .
it worked for me
I had this issue and nothing seemed to work.
I fixed it by downgrading node to version 12.14.1
Uninstall the current node version and install 12.14.1 from this link
Tried for Mac, it worked.. follow the steps for upgrading to the latest LTS
Before updating the Node.js release, check which version you are currently using with:
node -v
Next, clear npm cache with the command:
npm cache clean -f
Install n globally:
npm install -g n
Now that you have n installed, you can use the module to install the latest stable release of Node.js:
sudo n stable
Alternatively, you can install the Node.js release with the latest features:
sudo n latest
Or, install a specific version number with:
n [version.number]
I faced the same issue, so id run this command
npm config set legacy-peer-deps true
Then I simply created my react app using redux template by following
npx create-react-app app-name --template redux
worked for me!!
Its a little bit late but you can resolve this with --force or --legacy-peer-deps options. Either should work as mentioned in the error reported by npm
Try adding it with yarn. Worked for me

Cant build app using npx grunt on Windows

On Windows 8.1 installed Node.js 12.16.
First I run "npm install grunt" in a root directory of project.
Installation passed succesfully, however with the following warnings:
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion#
1, but npm-shrinkwrap.json was generated for lockfileVersion#0. I'll try to do m
y best with it!
npm WARN deprecated minimatch#0.2.14: Please update to minimatch 3.0.2 or higher
to avoid a RegExp DoS issue
npm WARN deprecated coffee-script#1.3.3: CoffeeScript on NPM has moved to "coffe
escript" (no hyphen)
npm WARN deprecated minimatch#0.3.0: Please update to minimatch 3.0.2 or higher
to avoid a RegExp DoS issue
npm WARN platform-web#0.0.1 No repository field.
npm WARN platform-web#0.0.1 No license field.
npm WARN The package time-grunt is included as both a dev and production depende
ncy.
npm WARN The package object-assign is included as both a dev and production depe
ndency.
+ grunt#0.4.5
added 38 packages from 47 contributors and audited 54 packages in 3.026s
found 25 vulnerabilities (5 low, 6 moderate, 14 high)
run `npm audit fix` to fix them, or `npm audit` for details
Root directory containts grunt-folder (root_dir/grunt), in which Gruntfile.js and package.json files are located.
And this grunt-folder containts other grunt-folder (root_dir/grunt/grunt). This second grunt containts some js-files.
Then in "root_dir/grunt" I run "npx grunt". But the build aborted with the following log:
>> Local Npm module "grunt-contrib-clean" not found. Is it installed?
>> Local Npm module "grunt-contrib-copy" not found. Is it installed?
>> Local Npm module "grunt-includes" not found. Is it installed?
>> Local Npm module "grunt-text-replace" not found. Is it installed?
>> Local Npm module "grunt-contrib-concat" not found. Is it installed?
>> Local Npm module "grunt-contrib-uglify" not found. Is it installed?
>> Local Npm module "grunt-contrib-cssmin" not found. Is it installed?
>> Local Npm module "grunt-file-creator" not found. Is it installed?
>> Local Npm module "grunt-war" not found. Is it installed?
>> Local Npm module "nexus-deployer" not found. Is it installed?
Warning: Task "clean:all" not found. Use --force to continue.
Aborted due to warnings.
package.json is
{
"name": "platform-web",
"version": "0.0.1",
"description": "Platform",
"devDependencies": {
"archiver": "^0.12.0",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-cssmin": "0.12.3",
"grunt-contrib-uglify": "^0.6.0",
"grunt-file-creator": "^0.1.3",
"grunt-includes": "^0.5.1",
"grunt-text-replace": "^0.4.0",
"grunt-war": "^0.5.1",
"nexus-deployer": "^0.1.8",
"object-assign": "^4.0.1",
"time-grunt": "^1.1.0"
},
"dependencies": {
"time-grunt": "^1.0.0",
"object-assign": "^4.0.1"
}
}
What am I doing wrong?
p.s.: root-folder is:
Following is only needed for older versions of grunt. New one install the bunstubbs correctly so you can still install grunt via npm and not globally.
Install grunt-cli. This will correctly pick up whichever version of grunt the project is running and execute it.
npm install grunt-cli --save-dev
In the package.json change dev script to
"scripts": {
"start": "npx grunt-cli"
}
then run
npm run start

npm install -g download all the dependencies again

I have package.json file, that contains 10 dependencies,
Every time I do npm install -g,all the dependencies are downloaded again, and this takes a long time.
Is there a way to take the existing dependencies from the local node_modules directory ?
This is my package.json dependencies:
"dependencies": {
"body-parser": "~1.16.0",
"colors": "^1.1.2",
"console-stamp": "^0.2.5",
"cookie-parser": "~1.4.3",
"dateformat": "^2.0.0",
"debug": "~2.6.0",
"express": "~4.14.1",
"ip": "^1.1.5",
"jade": "~1.11.0",
"lodash": "^4.17.4",
"morgan": "~1.7.0",
"nodemon": "^1.11.0",
"promise": "^8.0.1",
"rand-token": "^0.3.0",
"random-date-generator": "^1.0.2",
"restify": "^4.3.0",
"restify-cookies": "^0.2.2",
"serve-favicon": "~2.3.2"
}
Thanks,
npm install -g installs the current package context (i.e, the current working directory) as a global package. You do not need this for installing the project dependencies. Instead you can use npm install which will install/update dependencies in node_modules folder. By default, npm install will install all modules listed as dependencies in package.json and they do not install all dependencies every time and will only update when a change has been made to package.json or the node_modules folder is cleared out.
use npm install -g option to install packages globally like cordova, gulp, yeoman etc where you need them to be available throughout multiple projects.
Conceptually, the input to npm-install is a package.json, while its output is a fully-formed node_modules tree.
This shouldn't be an issue because npm uses the cache. It returns 304 if you have already installed the module, you can check it by applying --verbose with npm install command if given it's the same version of the dependency.
What I mean is:
$ npm install express
npm http fetch GET http://registry.npmjs.org/express
npm http fetch GET 200 http://registry.npmjs.org/express
at last, it shows:
++ express#4.16.2
added 49 packages in 12.547s
If you run it again then you will see
$ npm install express
npm http fetch GET http://registry.npmjs.org/express 408ms (from cache)
npm http fetch GET 304 http://registry.npmjs.org/express 408ms (from cache)
at last, it shows:
skipping write for package.json because there were no changes
++ express#4.16.2
updated 1 package in 4.11s
It hits the cache and won't download it again.
When running npm install for a second time on a project then it will not download it again only npm will check the first level of modules to ensure they're installed.
but not traverse the dependency tree to ensure all sub-module dependencies are installed. You can run npm outdated to check if modules are missing but npm won't install them for you.
npm update express updates the express module and its dependencies. So updates are when you already have the module and wish to get the new version. the update will always update to the latest version, regardless of package.json, while npm install will respect the version given in package.json.

npm install doesn't save dependency to package.json

It does add only when I execute: npm install <package_name> --save
In the documentation though: https://docs.npmjs.com/cli/install is written this:
By default, npm install will install all modules listed as dependencies in package.json.
Which is misleading.
npm install without arguments installs all dependencies (and dev dependencies) listed in the package.json file.
npm install --production installs all the dependencies (but no dev dependency)
npm install <package> installs a package and its dependencies.
npm install <package> --save installs a package and its dependencies, and adds it in the package.json file.
Edit: Since npm 5, --save is implied.
No, it's not. I think you are misreading the sentence.
npm install without any package name (as in your quote) will install all dependencies mentioned in the package.json.
Crete package.json file in your application folder.
Exp:- var/www/html/node/rest/package.json
{
"name": "node-api",
"main": "server.js",
"version": "0.0.1",
"dependencies": {
"express": "~4.0.0",
"mongoose": "~3.6.13",
"body-parser": "~1.0.1",
"mysql": "^2.5.4"
}
}
Then run npm install command your application folder
Exp:- var/www/html/node/rest npm install
You could run npm init again to update the dependencies info.

npm - unable to find local grunt or karma I just installed via package.json

I cannot find grunt, though I just installed it via package.json
My setup:
ph#vm:~$ uname -a
Linux vm 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
ph#vm:~$ which node
/usr/bin/node
ph#vm:~$ which npm
/usr/bin/npm
ph#vm:~$ node -v
v4.4.3
ph#vm:~$ npm -v
3.8.6
ph#vm:~$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
NODE_ENV="development"
#NODE_PATH=/usr/local/lib/node_modules
NODE_PATH=/usr/lib/nodejs:/usr/local/lib/node_modules:/usr/share/javascript
My package.json
{
...
"scripts": {
....
"pretest": "grunt lint",
"test": "karma start test/karma.conf.js",
...
"protractor": "protractor e2e-tests/protractor.conf.js",
},
"dependencies": {
....
"grunt": "^0.4.5",
...
},
"devDependencies": {
...
"karma": "~0.12.37",
....
"protractor": "~2.5.1",
...
}
}
Problem
After a npm install in the folder of package.json all the required packages are installed correctly in node_modules.
Running:
npm run protractor => works fine
npm run pretest = fails:
AND
npm run test => fails:
WITH
> grunt lint
sh: 1: grunt: not found
What's wrong with my setup?
I hope you install grunt globally . Thats why you getting error unable to find local grunt or karma. Sometimes We need both globally or locally so first install the grunt
Globally
npm install -g grunt-cli
After installation process done then you move to project folder and install the grunt locally.
locally
npm install grunt --save
npm install grunt-cli
For more info Click
npm install -g grunt-cli
This will install the grunt-cli tools, but also note the -g switch which installs it globally rather than just to your local node_modules directory.

Resources