Use dependencies from a private GitLab with NPM - node.js

I'm trying to install NPM dependencies from a private GitLab instence.
So, I have my repo with basic files
And I added this dependencie in the package.json on my project
"node-demo-package": "https://oauth2:<ACCESS TOKEN>#gitlab.fullurl.git"
But, when I run npm install, I receive this error message:
npm ERR! code ENOPACKAGEJSON
npm ERR! package.json Non-registry package missing package.json: node-demo-package#https://oauth2:<ACCESS TOKEN>#gitlab.fullurl.git.
npm ERR! package.json npm can't find a package.json file in your current directory.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/arnaud.delante/.npm/_logs/2018-01-24T15_05_49_456Z-debug.log
Which I don't understand as there is a package.json as showed in the screenshot.
Here it is
{
"name": "demo-package",
"version": "1.0.0",
"description": "Test pasckage",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git#gitlab.fullurl.git"
},
"author": "Arnaud Delante",
"license": "MIT"
}
I already tried switching https by git+https but I get another error
npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t https://oauth2:<ACCES TOKEN>#gitlab.fullrul.git
npm ERR!
npm ERR! remote: You are not allowed to download code from this project.
npm ERR! fatal: unable to access 'https://oauth2:<ACCES TOKEN>#gitlab.fullrul.git': The requested URL returned error: 403
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/arnaud.delante/.npm/_logs/2018-01-24T17_19_16_677Z-debug.log
Which is weird because the token is correct.
Would you have any idea?

In package.json try to replace https:// by git+https://
doc : https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

Related

npm install unauthorized error on install for private registry

I am trying to install a project and I get a npm 128 error code on one dependency of the project.
npm install
npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\mingw64\bin\git.EXE ls-remote -h -t git#gitlab.mysite.com:myprivaterepo
npm ERR!
npm ERR! Permission denied, please try again.
npm ERR! Permission denied, please try again.
npm ERR! git#gitlab.mysite.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
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!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2020-07-13T12_19_31_285Z-debug.log
I am normally using gitBash with agent running in background for ssh connections and I can directly clone from the gitLab repo of the incriminated dependency but i can't from the main project with npm install.
I also tried to execute the command that is throwing the error and it works:
git ls-remote --tags --heads git#gitlab.mysite.com:myprivaterepo
0099c1913ecc392394413554c5b22f2ea0b22b43 refs/heads/feature/generate-manifests
b67ca49f1d6ec9cf77ddd233a4f7b25d7a977d75 refs/heads/master
8787a2dafbfebef21a9cf77c8081b745979e76fe refs/heads/refactor/use-docker-compose-pull
70ee2ca3e44b6dedb4d4cf3984cec20dcf3283be refs/tags/1.0.0
9260ee68b9fd4972f18a51dc7c21d2a8559bc51e refs/tags/1.0.0^{}
fa44564e49035b5c1eecaeb9092332e60b5dfa0a refs/tags/1.0.1
0c3ef1ec8621614c83668841a69769c496d74ee4 refs/tags/1.0.1^{}
86a351644be3994f0bcd8b4cdbd2b9721d296440 refs/tags/1.0.2
f5c24db1d09cc3d35aa35816b8ad5528c60b6d79 refs/tags/1.0.2^{}
cc0b8bf529390eb9c1137aeeee82925b3f37c985 refs/tags/1.0.3
3002e6cce768eff4bdb6872b7856763065e0f545 refs/tags/1.0.3^{}
37fbaa00a3ffe116113af98243bb5abffd4e7d3a refs/tags/1.0.4
fac2008469dd9c1bb20b5a3d811586ee04527664 refs/tags/1.0.4^{}
d209098860a9f6f6b562431a065500bff2b2702f refs/tags/1.0.5
b67ca49f1d6ec9cf77ddd233a4f7b25d7a977d75 refs/tags/1.0.5^{}
Tried also with yarn and I have the same problem.
Tried also different node versions from the latest to the 8.0.0 or deleting and re-installing from scratch node and npm.
This is my package.json:
{
"name": "my-project",
"version": "1.0.0",
"description": "",
"main": "app/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "ssh://git#gitlab.mysite.com/myproject/myfolder"
},
"keywords": [
"my-keyword"
],
"author": "my#email.com",
"license": "mylicense",
"dependencies": {
"my-dependency": "git+ssh://git#gitlab.mysite.ch:my-repo/my-folder/my-repo",
"lodash": "^3.10.1",
"xml2js": "0.4.17"
}
}
Someone has any hint on what's the problem?
Hi Francesco and welcome to SO!
I think the problem is that the git process executed by npm runs out of the scope of your Git Bash, which is a MinGW. It looks like npm executes git.exe in pure windows context, hence it doesn't know anything about your MinGW environment. I would suggest you to place your ssh-keys both in ~/.ssh in Git Bash and in %USERPROFILE%\.ssh in windows. Or to create symbolic links on MinGW side.

Using NPM for SCSS but the script will not watch for changes. It gives me a error

I have installed Node v12.10.0, NPM v6.10.3. I have also tried to install the node LTS version as well.
I built my project directory and inside the directory I ran "npm init" and after I ran "npm install --save-dev node-sass". Everything seems good up to this point.
my package.json file looks like this
{
"name": "dashboard",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"scss": "node-sass --watch scss -o css"
},
"author": "",
"license": "ISC",
"devDependencies": {
"node-sass": "^4.12.0"
}
}
After I go to run " npm run scss" then I receive this.
> dashboard#1.0.0 scss /Users/adakaitalker/Documents/school/dev/learning/2-september/4-week/9:13:19/dashboard
> node-sass --watch scss -o css
sh: node-sass: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! dashboard#1.0.0 scss: `node-sass --watch scss -o css`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the dashboard#1.0.0 scss script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/adakaitalker/.npm/_logs/2019-09-13T22_43_56_711Z-debug.log
figured it out. I installed homebrew and linked it to node then I used homebrew to uninstall it and reinstall it and it works now.

Can't install any npm packages

I can't install any npm packages. I type in npm install lodash and I get:
npm WARN webdev#1.0.0 No description
npm WARN webdev#1.0.0 No repository field.
npm ERR! path C:\Users\Blake\Desktop\webdev\node_modules\lodash
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Blake\Desktop\webdev\node_modules\lodash' -> 'C:\Users\Blake\Desktop\webdev\node_modules\.lodash.DELETE'
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\Blake\AppData\Roaming\npm-cache\_logs\2018-03-15T21_28_45_978Z-debug.log
My package.json file looks like:
{
"name": "webdev",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
I'm not sure what is wrong. I've tried uninstalling and reinstalling node.js. My npm version is 5.6.0. This happens with every package I've tried to install. Please help, I've been trying to fix this for hours to no avail.
EDIT: I fixed it! The absolute nightmare of a program, MalwareBytes Antimalware was blocking it. I quit out of MalwareBytes and now it is working. Not the first time that program has messed up my coding.
Delete package.json and package-lock.json file, use npm init and try again.
Probably directory node_modules doesnt exist in your project working directory
I would make sure you have npm installed locally in your working directory by running npm init. I would also try re-installing npm.
EDIT:
Remove MalwareBytes Anti-Malware.

Publish npm, and after installation on other PC have error

and then install it on other pc to check. Bu after install package and it depencies i have error when try to start it
pm ERR! Linux 4.10.0-38-generic
npm ERR! argv "/home/pavlo/.nvm/versions/node/v6.11.4/bin/node" "/home/pavlo/.nvm/versions/node/v6.11.4/bin/npm" "start" "storjboard"
npm ERR! node v6.11.4
npm ERR! npm v3.10.10
npm ERR! path /home/pavlo/Desktop/test/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /home/pavlo/Desktop/test/npm-debug.log
Problem it that i have to clone package.json from git , how i can publish correctly with package.json?
Note: command start inside package.json scripts
My json for publish:
{
"name": "name",
"version": "0.0.3",
"description": "Name",
"main": "script.js",
"dependencies": {
"request": "^2.83.0",
},
"devDependencies": {},
"scripts": {
"test": "mocha",
"start": "node node_modules/module/script.js"
},
"repository": {
"type": "git",
"url": "https://github.com/me/module"
},
"keywords": [
"somewords"
],
"author": "me",
"license": "MIT",
"bugs": {
"url": "https://github.com/me/module/issues"
},
"homepage": "https://github.com/me/module#readme"
}
Error (WARN) when installing module on other PC
npm WARN enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm WARN test No description
npm WARN test No repository field.
npm WARN test No README data
npm WARN test No license field.
But in test/node_modules/module/(here there are everything) readme, json and script
If you want to be able to start your module from another directory, you can do it like this:
In your module package.json
{
"name": "module",
"scripts": {
"start": "node script.js"
}
}
from the test directory (as this answer suggest):
npm start --prefix node_modules/module/
Alternately, you can start your module by creating a package.json file in your test directory and adding a script:
{
"name": "test",
"scripts": {
"start": "node node_modules/module/script.js"
}
}
Usally npm packages are placed in node_modules directory because those modules are supposed to be used as dependencies, not directly.
It depends on the purpose of your application, but maybe you might be interested in doing a post-install script or installing it globally.
npm doc for packages installation.

why I am unable to publish my package to npmjs

I have created an account with npmjs.com also I'm following the how-to-npm tutorial from command line (linux). I'm at the stage where I should publish my test module. But I keep getting error:
You must sign up for private packages : #zentech/node
these are all the error when npm publish
npm ERR! publish Failed PUT 402
npm ERR! Linux 4.10.0-33-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "publish"
npm ERR! node v4.7.2
npm ERR! npm v3.5.2
npm ERR! code E402
npm ERR! You must sign up for private packages : #zentech/node
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /home/george/node/npm-debug.log
my package.json file
{
"name": "#zentech/node",
"version": "1.0.1",
"main": "index.js",
"preferGlobal": true,
"scripts": {
"test": "node test.js"
},
"author": "",
"license": "ISC",
"description": "",
"repository": "http://github.com/zentech/node"
}
does anyone know why the error? thanks
As suggested in the comments above the way to publish a scoped package i.e.
#scope/my-package
is to use the --access flag when publishing
npm publish --access=public
You do not need to sign up for private packages unless you actually want your package to be private.
Or you can set the public access on package.json:
{
...
"publishConfig": {"access": "public"}
...
}
rather than:
{
...
"publishConfig": {"access": "restricted"}
...
}
You must sign up for private packages: #zentech/node
So you either sign up, or you change the name of your package from #zentech/node to a public name, like zentech-node.

Resources