In my project, I have a requirement where I need to publish a package to 2 registries.
Currently, whenever I need to publish, I do the following steps.
npm config set registry https://registry.npmjs.org/ and then npm publish.
npm config set registry http://npm-registry.myorg.com and then npm publish
This becomes a tiring process for me as there are a lot of new changes that I publish. So I thought of reducing some work by creating a script in package.json which can do this automatically.
This is what I added.
{
scripts: {
"deploy:private": "npm config set registry http://npm-registry.myorg.com && npm publish",
"deploy:public": "npm config set registry https://registry.npmjs.org/ && npm publish"
}
}
So when I run yarn deploy:private, it gives below to me
npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`
How can I resolve this, please help?
----------UPDATE-----------
After googling I have found this https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow
Based on this I have set my token as env variable and in the project I have created a local .npmrc, with below contents
.npmrc file
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
//npm-registry.tokopedia.com/:_authToken=${NPM_TOKEN_PRIVATE}
But still, I get the error when I try to run the above commands.
Related
I am trying to publish a package to a private Gitlab npm registry. I am following gitlab's docs on how to do this, but something isn't working right.
First, I created a personal access token with all access. Then, in my terminal, as per their docs, I set
npm config set #myproject/my_package http://gitlab.com/api/v4/projects/myproject/my_package/packages/npm/
npm config set -- http://gitlab.com/api/v4/projects/myproject/my_package/packages/npm/:_authToken "<my_token>"
Though there is no output from these commands, so I'm not really sure what its doing or if its working as intended.
Next, in my package.json, I set the name and publishConfig to what you would expect for a scoped package:
{
"name": "#myproject/my_package",
"publishConfig": {
"access": "restricted",
"#myproject/my_package": "https://gitlab.com/af56/myproject/my_package/packages/npm/"
}
}
I then run npm publish. I see that the package is being built, but then I get an error
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/npm ERR!
need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\me\AppData\Local\npm-cache\_logs\2022-11-09T00_00_38_418Z-debug-0.log
I don't understand why npm is trying to reach npmjs when I configured it to use gitlab as the registery, both through the command line, and in the package.json. I've published packages to npmjs before, but never to gitlab registry, so I'm not sure what steps I'm missing / doing wrong.
Issue:
I'm trying to publish my npm package https://www.npmjs.com/package/react-native-ultimate-modal-picker and it's coming up with the error. It's been 9 months since I last have made a publish and I just updated a ton of code and files. I also set the publishing from NPM to GitHub, but I think I reverted those changes?
Question:
Why am I getting the errors below?
How can I make sure that the npm package is published to https://www.npmjs.com/package/react-native-ultimate-modal-picker?
Errors:
org.couchdb.user:jefelewis' is not in the npm registry.
This package name is not valid, because
npm ERR! 404 1. name can only contain URL-friendly characters
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
Process:
npm login
Enter login info (Username: jefelewis)
org.couchdb.user:jefelewis is not in the npm registry.
The issue is that my username is jefelewis (https://www.npmjs.com/~jefelewis)
Update:
This was fixed by using npm config set registry https://registry.npmjs.org/ in the terminal
I want to publish a private npm package with Gitlab CI.
I've created an auth token for my npm user and set it as a variable NPM_TOKEN in my Gitlab CI settings.
The job then creates an .npmrc file with the registry and the auth token.
- npm run build && npm run build:es6
- echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>.npmrc
- npm publish
The job fails with this message:
npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`
Is it possible to publish with only an auth token?
As #Amityo said, rather than manually editing the npmrc file,
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
is the way to go, because otherwise you may be editing the wrong npmrc file.
If you are still getting an authentication error, and are certain that the token is correct, check your registry URL. You can run
npm publish --verbose
whose output will includes lines like
npm verb getPublishConfig { registry: 'https://.......' }
npm verb mapToRegistry no registry URL found in name for scope #boxine
npm verb publish registryBase https://.......
If you are publishing to npmjs.org, the URL (....... above) should be https://registry.npmjs.org/ .
If this registry URL does not fit, look in your npmrc file for a different one. Also make sure you didn't override the registry in your package.json file! You can search for publishConfig in that file.
To elaborate slightly on #phihag's answer, forward slashes are very important.
At first I kept getting 404 not found
$ npm publish
...
...
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://gitlab.company.com/api/v4/packages/npm/%2fmypackage - 404 Not Found
npm ERR! 404
npm ERR! 404 '#scope/mypackage#0.1.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
I am using 2FA so as the gitlab docs state, I need to use a personal access token set to api to authenticate. In another part of the gitlab docs it states
Some features such as publishing a package is only available on the project-level endpoint.
So in console I tried to publish to and authenticate at the project level
$ npm config set #scope:registry https://gitlab.company.com/api/v4/projects/123/packages/npm
$ npm config set //gitlab.company.com/api/v4/projects/123/packages/npm:_authToken 'MyGeneratedAccessToken'
Which eliminated my first issue of 404 not found, but now I couldn't authenticate.
For hours.
$ npm publish --verbose
npm verb cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'publish', '--verbose' ]
npm info using npm#7.11.2
npm info using node#v15.11.0
...
...
npm verb publish [ '.' ]
npm notice
npm notice 📦 #scope/mypackage#0.1.0
npm notice === Tarball Contents ===
npm notice 214B README.md
npm notice 1.1kB package.json
npm notice === Tarball Details ===
npm notice name: #scope/mypackage
npm notice version: 0.1.0
npm notice filename: #scope/mypackage-0.1.0.tgz
npm notice package size: 764 B
npm notice unpacked size: 1.3 kB
npm notice shasum: c22a42756de43e282da01f33c7d5da4940c7d1d7
npm notice integrity: sha512-l/P2cr52Lle7h[...]isu3rDME3lYuQ==
npm notice total files: 2
npm notice
npm verb stack Error: This command requires you to be logged in.
npm verb stack at Publish.publish (/usr/local/lib/node_modules/npm/lib/publish.js:104:29)
npm verb cwd /home/user/Workspace/mypackage
npm verb Linux 5.8.0-43-generic
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "publish" "--verbose"
npm verb node v15.11.0
npm verb npm v7.11.2
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm verb exit 1
npm timing npm Completed in 352ms
npm verb code 1
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2021-05-12T11_23_19_273Z-debug.log
As you can see, npm publish --verbose isn't being helpful in telling me the URL i'm trying to publish to. Checking the documentation again showed I was missing the trailing slashes after 'packages/npm'.
With the trailing slashes, I was able to publish to the gitlab npm package repository for that project
$ npm config set #scope:registry https://gitlab.company.com/api/v4/projects/123/packages/npm/
$ npm config set //gitlab.company.com/api/v4/projects/123/packages/npm/:_authToken 'MyGeneratedAccessToken'
And for all packages I use
$ npm config set #scope:registry https://gitlab.company.com/api/v4/packages/npm/
$ npm config set //gitlab.company.com/api/v4/packages/npm/:_authToken 'MyGeneratedAccessToken'
I had the same issue for npm publish. I tried with yarn publish and it also failed.
It was successful when I ran:
yarn publish --non-interactive
Also, I had an issue related to .husky (cannot install husky) and it was solved running before yarn publish this command with npm:
npm set-script prepare ''
Started using angular2 with .NET Core and I'm trying to get continuous integration going on the build servers.
We are running TFS2013 so it's a XAML build definition. Since I don't want the node_modules folder checked in to source control, I'm attempting to run npm install in a powershell script before the build starts.
When I do this I get the following
npm ERR! 404 Not found : #progress/kendo-angular-dropdowns npm ERR!
404 npm ERR! 404 '#progress/kendo-angular-dropdowns' is not in the
npm registry. npm ERR! 404 You should bug the author to publish it
(or use the name yourself!) npm ERR! 404 It was specified as a
dependency of 'angular2-webpack' npm ERR! 404 npm ERR! 404 Note that
you can also install from a npm ERR! 404 tarball, folder, http url,
or git url.
On Telerik's site they say you need to enable the NPM registry by running this in the console
npm login --registry=https://registry.npm.telerik.com/ --scope=#progress
This requires you to provide account details though.
I've done this on the build server and I'm able to run npm install successfully from the command line, but no such luck when attempting it from the powershell script in MSBuild.
Any help would be greatly appreciated.
The error is most likely caused by the registry not available to the build script.
Make sure that there is a .npmrc file that specifies the registry and the auth token, not unlike this:
#progress:registry=https://registry.npm.telerik.com/
//registry.npm.telerik.com/:_authToken=long_secret_token_here
... and that the file is honored by MsBuild.
I have a Java spring as server stack and with angularJS for the UI stack.
Part of the build process I need Jenkins to run Grunt build to optimize the UI before the build process starts.
I have tried to install Yeoman on the Jenkins instance but since I am not the administrator I am getting Access errors.
[\> npm install -g yo
npm ERR! Error: EACCES, mkdir '/var/lib/openshift/<ID>/.npm'
npm ERR! { [Error: EACCES, mkdir '/var/lib/openshift/<ID>/.npm']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/var/lib/openshift/<ID>/.npm' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
You're getting an access error because you're trying to do a global install - that's what the -g flag does. In other words, you're attempting to install yeoman in a system-wide location instead of locally, which requires root permissions.
Also, you shouldn't need to install yeoman in a production environment - yeoman just does app scaffolding. If you're using yeoman locally, it should have added grunt, and any grunt plugins you need, to the package.json file in your app. Make sure the package.json file is checked in, then as part of the build process, you can run npm install, then grunt build.
I'm not sure how Jenkins affects the build process, but normally, npm install will run automatically when you push a new commit to your OpenShift app.