NPM Install won't use my provided git url - node.js

I have a dev dependancy in my package.json file that points to a local gitlab repository.
"devDependencies": {
"browser-sync": "^1.2.1",
"event-stream": "^3.1.5",
...
"mymodule": "git+http://my.gitlab.url/team/repo.git",
...
"run-sequence": "^0.3.6"
}
This does not work. When I look in the npm-debug.log file, it seems that instead of cloning the repo from gitlab, its trying to find it in the npm repository:
26 http GET https://registry.npmjs.org/mymodule
27 http 404 https://registry.npmjs.org/mymodule
Then of course further down in the file:
32 error 404 404 Not Found: mymodule
32 error 404
32 error 404 'mymodule' is not in the npm registry.
32 error 404 You should bug the author to publish it
If i run git clone to get the contents of the repo it works. If I run "npm install" followed by the path in the package.json file it works. But it does not work when I run a simple "npm install".
Can anyone explain why?
So..... why does it not honour the gitlab path in my package.json when I run "npm install"?

The error messages are a red herring. This was caused by app level inspection (and blocking) on our firewall. Answer here as a "something to check with your security guys" for the next person.

Related

NPM ERR Code E401: Unable to authenticate, need: Bearer authorization

I downloaded a NodeJS application from GitHub and facing the following error when executing npm install.
npm ERR! code E401
npm ERR! Unable to authenticate, need: Bearer authorization_uri=https://login.windows.net/c1156c2f-a3bb-4fc4-ac07-3eab96da8d10, Basic realm="https://pkgsprodeus21.pkgs.visualstudio.com/", TFS-Federated
My Node version is 6.13.1 and NPM version is 6.13.4.
Following is the content of package.json file:
{
"name": "DemoApp",
"version": "1.0.0",
"description": "A social oasis for lovers of pizza.",
"repository": "****",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "****",
"license": "MIT",
"dependencies": {
"#hapi/boom": "7.4.2",
"#hapi/catbox": "10.2.1",
"#hapi/catbox-redis": "5.0.2",
"#hapi/cookie": "10.1.0",
"#hapi/good": "8.2.0",
"#hapi/good-squeeze": "5.2.0",
"#hapi/hapi": "18.3.1",
"#hapi/inert": "5.2.1",
"#hapi/joi": "15.1.0",
"#hapi/vision": "5.5.2",
"aws-sdk": "2.488.0",
"bcryptjs": "2.4.3",
"bootflat": "2.0.4",
"fs-extra": "8.1.0",
"handlebars": "4.1.2",
"lodash": "4.17.13",
"pg": "7.11.0",
"sequelize": "5.9.4"
}
}
I have been stuck at this issue since yesterday and still no luck finding the solution.
Any help would be highly appreciated.
This is what worked for me.
First, delete the .npmrc file in your Users folder. This folder:
C:\Users\[your user name]
Then run this command in your project folder that has an .npmrc file in it:
npx vsts-npm-auth -config .npmrc
Use npm install --registry https://registry.npmjs.org instead of npm install
No need to delete the .npmrc file, the following worked for me
npm logout
Then
vsts-npm-auth -config .npmrc
If you get E401 with a private npm registry after upgrading to npm v7, remove your package-lock.json and reinstall.
The registry url setting in .npmrc needs to match the http/https protocol in your package-lock.json exactly.
Or as Stuart pointed out: find and replace to update the existing lock file with the correct URL
Worked for me:
Delete the yarn.lock/package-lock.json files
npm install
I had the same issue, my discovery was as follows:
The application node.js version was 14.0
but the node version in my machine was 16.0.
I had to install the node the version 14.0 to resolve the issue.
To manage multiple node versions this tool is highly recommended.
windows - Nvm for windows
Linux - Nvm for Linux
I had this exactly same error and turned out it was an issue with personal access token (PAT). Renew your PAT and run vsts-npm-auth.
Delete old .npmrc file from user home directory and then run the following command
vsts-npm-auth -config .npmrc -T $HOME/.npmrc
This issue comes from a wrong configuration in your .npmrc file. I had a slightly different error so I'm sharing it here.
In my case the exact error was:
Unable to authenticate, need: Bearer realm="<registry>", Basic realm="<registry>"
My npmrc file should connect to a private npm registry and looked like this:
registry=https://<private-registry>
//<private-registry>:_authToken=<token>
//<private-registry>:always-auth=true
The issue was that I needed to add the https:// protocol also to the second and third line and it worked. In the end it looked like this:
registry=https://<private-registry>
//https://<private-registry>:_authToken=<token>
//https://<private-registry>:always-auth=true
I solved it running this command:
npm logout/npm login
I had the same error with our company registry configured in .npmrc
registry=https:<compnay-registry-url>
Node version : 16.10.0
NPM version : 7.24.0
Solution:
Execute npm login
$ npm login
npm notice Log in on https:<registry-url>
Username: xxxx
Password:
Email: (this IS public) (xxxx)
Logged in as xxx on https:<registry-url>.
After this .npmrc got updated with
//<registry-url>/:_authToken=xxxxx
If you are trying to install any package from your private repo and you are getting this error with npm i package_name command then
1. remove your package-lock.json from the the directory where to tried to create the package from
2. reinstall dependencies: npm i
this will resolve the issue.
I had the same issue caused by an expired token in the .npmrc file in my project directory. Sadly the error is very unspecific on what causes the auth error.
This worked for me. I just logged in again in NPM and the problem was solved
npm login
After u write your username and password execute again
npm install
For me the the problem was in .npmrc file the key password needed to be changed to _password then npm install worked.
Using a Mac and Azure - it was because my Personal Access Token (PAT) had expired and it didn't let me know.
Open your .npmrc with your auth tokens in.
Go to your azure repo and click your profile and then personal access tokens.
Create a new token.
Open terminal and run:
node -e "require('readline') .createInterface({input:process.stdin,output:process.stdout,historySize:0}) .question('PAT> ',p => { b64=Buffer.from(p.trim()).toString('base64');console.log(b64);process.exit(); })"
Paste your PAT in and press Enter
Copy the Base64 encoded value into your .npmrc password.
Had the same error.
In my case, the initial project including package-lock.json file was composed with NodeJS version 12 and npm version 6.
But trying to run npm install on my local machine with NodeJS version 16 and npm version 7 was causing this problem.
My solution was installing dependencies with the initial version of NodeJS. I used docker to get the correct version, run this command from the root directory of your project (where the package.json file is located):
docker run --rm -it \
-w /app \
-v $PWD/:/app \
node:12 \
npm install
If you do not have docker installed, you can try using nvm.

Why is Heroku telling me it cannot find a package.json in my module when I do a heroku push

I created my own npm package from a fork of react-coverflow. It appears to be working fine in my app locally using it this way: "npm install react-coverflow-mod" --save.
I can run my app using "run with debug (F5)" in VsCode and npm start on the client folder to start the React front end.
Then I do an npm run build on the client folder, and it works just fine.
When I do a heroku push it fails everytime with this error:
npm ERR! code ENOLOCAL
npm ERR! Could not install from "../../react-coverflow-mod"
as it does not contain a package.json file.
1. I know there is a package.json in the module because I can install it via "npm install react-coverflow-mod": https://www.npmjs.com/package/react-coverflow-mod
2. The installed module has a package.json file in it
3. My github repo has a package.json in it: https://github.com/leroyvaughan/react-coverflow
I'm not sure how I can fix this. Do I need a package.json to go into the /Dist folder? What is wrong here with Heroku.
It seams like heroku try to install a package from a relative path instead of the published name. That would perfectly explain why you can run locally but not on a production environment.
Open your project and search for the exact string displayed in your log: "../../react-coverflow-mod" and you should be able to find quickly where it is.
If you run on a unix system (don't know about windows) you can do a search using grep:
grep -rnw '/path/to/somewhere/' -e '../../react-coverflow-mod'
Make sure it includes your root folder which contain package.json, and might we wise to ignore node_modules which is always massive.

Travis CI and Grunt Error: Grunt build failed and exited with 99 during '.'

I am trying to integrate Travis CI with a repository(forked on github). Everything is fine but Travis CI website is showing the following error under Job.
Fatal error: Unable to find local grunt.
The command "grunt build" failed and exited with 99 during .
I have added npm install in my .travis.yml and also defined script in my package.json file.
The grunt dependencies and gruntfile.js has also been properly set up.
Unable to find local grunt.
Is pretty explicit. Just add grunt to the dependencies of your package.json or run
npm i --save grunt
EDIT: OP's problem was actually due to a missing package.json at the root of the project.

npm "failed to parse json"

When I'm trying to install express with npm I always get the following error:
Failed to parse json
No data, empty input at 1:1
File: /root/.npm/inherits/2.0.1/package/package.json
Failed to parse package.json data.
package.json must be actual JSON, not just JavaScript.
This is not a bug in npm.
Tell the package author to fix their package.json file. JSON.parse
What am I doing wrong?
sudo npm install -g express
OS is Ubuntu 12.04 (precise) armhf
Thanks to Jivings from this comment:
npm cache clean
solved the problem.
I had the same problem but "npm cache clean" didnt resolve it for me. I had to go back to my package.json and realize i had comma where it shouldn't i suppose as shown below:
},
"devDependencies": {
"axios": "^0.15.3",
"bootstrap-sass": "^3.3.7",
"cross-env": "^3.2.4",
"jquery": "^3.1.1",
"laravel-mix": "0.*",
"lodash": "^4.17.4",
"vue": "^2.1.10",
}
after the "vue..." so I deleted that and every went back to normal. So it is worth checking the package.json file first before running npm cache clean
Mostly, this error is due to a syntax error in package.json file.
In my case, the opening curly brace for dependencies object in package.json was missing:-
Code--------------------------------
{
"name": "psrxjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies":
"rxjs": "^5.4.3"
}
}
In Laravel project:
Delete 'node_modules' folder;
npm cache clean
npm update
I solved the issue using below steps:
Delete node_modules folder
Delete package-lock.json file
Run npm install
Run npm start
I also got the same error message while run npm install, first run npm package.json to check errors in package.json file, if not then run npm cache clean
You could get this error from not doing npm init.
I faced this problem several times before I got used to using NPM. Most off the time it was because I failed to use npm init before npm install
For me the issue was fixed by changing the name of the package
from
"name": "portfolio"
to
"name": "portfolio2"
I experienced a similar issue today after updating Node on Windows 10. My local build tasks started failing and upon investigation I saw all these errors in my dependency package.json files. None of them were valid JSON anymore and I was seeing messages like:
npm WARN Failed to parse json
npm WARN Unexpected token '\u0019' at 1:1
npm WARN ������2�����bE�;���1L �\5�e���k2?��,?;��쏏a��(T��w��+I��/�6�P} ��i�|e�
npm WARN ^
in my console.
This story has a happy ending as it turns out that new Node doesn't play nice with old NPM and updating NPM to version 5 solved the problem. Hope this helps other folks who may experience this variation on this issue.
The following bash script fixes the problem automatically
#!/usr/bin/env bash
echo -e '#!/usr/bin/env bash' > npm_install.sh
cat npm-debug.log | grep 'error File:' | sed -n 's:.*error File\: \(.*\):echo "Removing \1"\nrm -f \1\necho "Cleaning npm cache"\nnpm cache clean\necho "Reinstalling npm"\nnpm install\n./npm_reinstall.sh:p' >> npm_install.sh
chmod +x npm_install.sh
./npm_install.sh
It should be saved to npm_reinstall.sh
and granted execution permissions using
chmod +x npm_reinstall.sh
The script is preforming the following tasks:
Looking for an error File : in npm-debug.log using grep
Using sed to generate the fix commands 3-5 only if there are errors
Removing the empty file rm -f /1 = file path from the first group in regular expression .*error File: (.*)
Cleaning npm cache npm cache clean
Reinstalling npm npm install
Running ./npm_reinstall.sh recursively till no errors are found
More information about npm install can be found at npm-install command documentation
In my case
Missing a comma somewhere in a package.json Check your package.json file.
After that sudo npm install
or
To clean the cache memory.
sudo npm cache clean
In addition to Pank's answer, if you encounter this kind of error
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token } in JSON at position 550 while parsing near '...eact": "^7.12.4",
npm ERR! JSON.parse },
npm ERR! JSON.parse "dependencies":...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
You need to make sure your package.json is a valid json, not a javascript.
Please check with unused white spaces inside package.json file, it might cause by extra white spaces.
I think you may be did some change in package.json and that is not valid
Delete node_modules
Delete package.json
Create a new NPM package with
npm init
install all of your package once again
npm install express
For those of you who are new to this like me, I forgot to initialize my JSON package with the npm init command.
remove any unnecessary comments, the error you referred occurs usually due to the syntax error. Or if this won't help, try to clean the cache by "npm cache clean".
1.Basically it comes for wrong placement of comma so remove comma at wrong position(esp error occurs for placing comma(,) before closing flower brace('}') in package.json so look into it. This is one solution
Run
sudo npm cache clean
sudo chown -R 1000:1000 "...path/.npm"
Don't forget to edit your package.json, escpeially the dependencies.
For example, one of my chatting room projects needs the following content in package.json:
{
"name":"chatrooms",
"version":"0.0.1",
"description":"Minimalist multi-room chat server",
"dependencies":{
"socket.io":"~0.9.6",
"mime":"~1.2.7"
}
}
Try to open your txt editor and select "plain text" for the package.json then re-save. Sometimes issue is overlooked and simple things are holding the answer.

Yeoman webapp errors on default build

I'm using the webapp generator and I'm getting errors on a default build.
I create a new directory and run
yo webapp
Then
grunt
And finally
grunt server:dist
The Chrome console gives me the following errors:
Allo 'Allo! a53234b6.main.js:3
Running jQuery 1.10.2 a53234b6.main.js:3
Failed to load resource http://127.0.0.1:35729/livereload.js?snipver=1
Failed to load resource: the server responded with a status of 404 (Not Found) http://127.0.0.1:9000/modules/a53234b6.main.js
Uncaught Error: Script error for: a53234b6.main
http://requirejs.org/docs/errors.html#scripterror skitch.js:354
Am I using the wrong commands? Do I need to update node, npm, yeoman, etc? This is an awesome tool, but I might need to switch back to manual mode b/c I can't troubleshoot it very well
In your package.json, under devDependencies, add the following:
"devDependencies": {
...
"grunt": "~0.4.2",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
...
"grunt-contrib-watch": "~0.5.2",
...
"grunt-contrib-livereload": "0.1.2", // <- add this line
Then:
$> npm install
$> bower install
$> grunt server

Resources