On Premise Agent does not download all NPM packages - npm

Edit: 2018-02-28 - add screen shot of build definition
I am having a problem with an on premise VSTS Agent. When 'npm install' runs, it only installs about 20% of the packages. the command does not error out. If I run the same NPM install command when I remote into the machine all the packages are installed. I used the same steps manually that are in the Visual Studio Team Services Hosted Images scripts. Specifically Install-NodeLts.ps1
I need to get the local agent running so our builds will complete.
npm/5.6.0 node/v8.9.4 win32 x64
You can see below it says: 'added 559 packages in 37.875s', but when run npm install from command line via RDP, it installs 2419 packages.
I have tried:
re-install NPM as a task
run npm install twice as two different tasks
run npm install from a command task
run agent as my same user account
Partial output log:
2018-02-27T21:30:59.6386335Z ##[section]Starting: npm install
2018-02-27T21:30:59.6396849Z ==============================================================================
2018-02-27T21:30:59.6397102Z Task : npm
2018-02-27T21:30:59.6397398Z Description : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Package Management.
2018-02-27T21:30:59.6397690Z Version : 1.0.10
2018-02-27T21:30:59.6397884Z Author : Microsoft Corporation
2018-02-27T21:30:59.6398144Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613746)
2018-02-27T21:30:59.6398400Z ==============================================================================
2018-02-27T21:31:00.7066189Z [command]C:\WINDOWS\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" --version"
2018-02-27T21:31:02.6879301Z 5.6.0
2018-02-27T21:31:07.0100259Z [command]C:\WINDOWS\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" config list"
2018-02-27T21:31:09.1937476Z npm info it worked if it ends with ok
2018-02-27T21:31:09.1938350Z npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
2018-02-27T21:31:09.1938614Z npm verb cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
2018-02-27T21:31:09.1938859Z npm verb cli 'prefix',
2018-02-27T21:31:09.1939038Z npm verb cli '-g' ]
2018-02-27T21:31:09.1939210Z npm info using npm#5.6.0
2018-02-27T21:31:09.1939414Z npm info using node#v8.9.4
2018-02-27T21:31:09.1939594Z npm verb exit [ 0, true ]
2018-02-27T21:31:09.1939806Z npm info ok
2018-02-27T21:31:09.1940065Z npm info it worked if it ends with ok
2018-02-27T21:31:09.1940314Z npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
2018-02-27T21:31:09.1940577Z npm verb cli 'C:\\npm\\prefix\\node_modules\\npm\\bin\\npm-cli.js',
2018-02-27T21:31:09.1940790Z npm verb cli 'config',
2018-02-27T21:31:09.1941046Z npm verb cli 'list' ]
2018-02-27T21:31:09.1941258Z npm info using npm#5.6.0
2018-02-27T21:31:09.1941470Z npm info using node#v8.9.4
2018-02-27T21:31:09.1941711Z npm verb exit [ 0, true ]
2018-02-27T21:31:09.1941956Z npm info ok
2018-02-27T21:31:09.1942165Z ; cli configs
2018-02-27T21:31:09.1942384Z metrics-registry = "https://registry.npmjs.org/"
2018-02-27T21:31:09.1942647Z scope = ""
2018-02-27T21:31:09.1942849Z user-agent = "npm/5.6.0 node/v8.9.4 win32 x64"
2018-02-27T21:31:09.1942977Z
2018-02-27T21:31:09.1943141Z ; environment configs
2018-02-27T21:31:09.1943350Z cache = "C:\\npm\\cache"
2018-02-27T21:31:09.1943529Z loglevel = "verbose"
2018-02-27T21:31:09.1943712Z prefix = "C:\\npm\\prefix"
2018-02-27T21:31:09.1943927Z userconfig = "D:\\VSTSAgent\\vsts-agent-win-x64-2.129.1\\_work\\2\\npm\\187.npmrc"
2018-02-27T21:31:09.1944096Z
2018-02-27T21:31:09.1944268Z ; builtin config undefined
2018-02-27T21:31:09.1944399Z
2018-02-27T21:31:09.1944626Z ; node bin location = C:\Program Files\nodejs\node.exe
2018-02-27T21:31:09.1944941Z ; cwd = D:\VSTSAgent\vsts-agent-win-x64-2.129.1\_work\2\s\Web
2018-02-27T21:31:09.1945215Z ; HOME = C:\Users\bolducp
2018-02-27T21:31:09.1945445Z ; "npm config ls -l" to show all defaults.
2018-02-27T21:31:09.1945592Z
2018-02-27T21:31:09.1947815Z [command]C:\WINDOWS\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" install"
2018-02-27T21:31:50.2618021Z npm info it worked if it ends with ok
2018-02-27T21:31:50.2618358Z
2018-02-27T21:31:50.2623471Z > react-bootstrap-select#0.14.0 postinstall D:\VSTSAgent\vsts-agent-win-x64-2.129.1\_work\2\s\Web\node_modules\react-bootstrap-select
2018-02-27T21:31:50.2624421Z npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
2018-02-27T21:31:50.2624674Z > jsx jsx/ dist/
2018-02-27T21:31:50.2624944Z npm verb cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
2018-02-27T21:31:50.2625391Z
2018-02-27T21:31:50.2625873Z ["Select"]
2018-02-27T21:31:50.2627029Z added 559 packages in 37.875s
2018-02-27T21:31:50.2636988Z npm verb cli 'prefix',
2018-02-27T21:31:50.2637434Z npm verb cli '-g' ]
2018-02-27T21:31:50.2639621Z npm info using npm#5.6.0
2018-02-27T21:31:50.2639731Z npm info using node#v8.9.4
2018-02-27T21:31:50.2639837Z npm verb exit [ 0, true ]
2018-02-27T21:31:50.2640063Z npm info ok
2018-02-27T21:31:50.2640199Z npm info it worked if it ends with ok
2018-02-27T21:31:50.2640352Z npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
2018-02-27T21:31:50.2640480Z npm verb cli 'C:\\npm\\prefix\\node_modules\\npm\\bin\\npm-cli.js',
2018-02-27T21:31:50.2640597Z npm verb cli 'install' ]
2018-02-27T21:31:50.2640700Z npm info using npm#5.6.0
2018-02-27T21:31:50.2640835Z npm info using node#v8.9.4
2018-02-27T21:31:50.2640945Z npm verb npm-session 7bedb538a9b4e7b7
2018-02-27T21:31:50.2641065Z npm info lifecycle company-project#1.0.0~preinstall: company-project#1.0.0
2018-02-27T21:31:50.2641230Z npm http fetch GET 304 https://registry.npmjs.org/moment 375ms (from cache)
...
2018-02-27T21:31:50.3412460Z npm verb exit [ 0, true ]
2018-02-27T21:31:50.3412559Z npm info ok
2018-02-27T21:31:50.3416231Z ##[section]Finishing: npm install

When setting up the hosted agent, I had modified the build definition to include an environment variable NODE_ENV=production. When the NODE_ENV environment variable is set to production, npm will not install modules listed in devDependencies.

Related

Getting Bad Request (Http 400) when using npm dist-tag with Nexus 3.19.1-01

We are running Nexus OSS 3.19.1-01 (CentOS7 with OpenJdk 1.8.0_222-b10) with npm repository. Everything works fine except the npm dist-tag feature which should now work with version >3.19.
$ npm publish <pkg> --tag bla #--> works
$ npm install <pkg>#bla #--> works
$ npm dist-tag ls <pkg> #--> works
$ npm dist-tag rm --verbose #myscope/mypackage foo
npm info it worked if it ends with ok
npm verb cli [
npm verb cli '/usr/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli 'dist-tag',
npm verb cli 'rm',
npm verb cli '--verbose',
npm verb cli '#myscope/mypackage',
npm verb cli 'foo'
npm verb cli ]
npm info using npm#6.13.1
npm info using node#v12.13.0
npm verb npm-session 3b193197390df1cf
npm verb dist-tag del snapshot from #myscope/mypackage
npm http fetch GET 200 https://nexus.example.com/repository/npm-group/-/package/#myscope%2fmypackage/dist-tags 1396ms
npm http fetch DELETE 400 https://nexus.example.com/repository/npm-group/-/package/#myscope%2fmypackage/dist-tags/foo 9ms
npm verb stack Error: 400 Bad Request - DELETE https://nexus.example.com/repository/npm-group/-/package/#myscope%2fmypackage/dist-tags/foo
npm verb stack at /usr/local/lib/node_modules/npm/node_modules/npm-registry-fetch/check-response.js:104:15
npm verb stack at processTicksAndRejections (internal/process/task_queues.js:93:5)
npm verb statusCode 400
npm verb pkgid #myscope/mypackage#latest
npm verb cwd /home/myname/path-to-code/mypackage/client
npm verb Linux 5.3.11-300.fc31.x86_64
npm verb argv "/usr/bin/node" "/usr/local/bin/npm" "dist-tag" "rm" "--verbose" "#myscope/mypackage" "foo"
npm verb node v12.13.0
npm verb npm v6.13.1
npm ERR! code E400
npm ERR! 400 Bad Request - DELETE https://nexus.example.com/repository/npm-group/-/package/#myscope%2fmypackage/dist-tags/foo
npm verb exit [ 1, true ]
npm timing npm Completed in 1730ms
npm ERR! A complete log of this run can be found in:
npm ERR! /home/myname/.npm/_logs/2019-11-20T13_02_41_234Z-debug.log
$ npm dist-tag add #myscope/mypackage#0.1.0 bar
# did not work, same error as above
No additional log messages in nexus log.
Any idea?
I'm afraid it won't work for you, because you're running your commands against npm group repository. Both npm dist-tag add and npm dist-tag rm work only for hosted repositories as of NXRM 3.19.1. However, npm dist-tag ls is supported by all types of repositories (since 3.19.0).

npm install windows-build-tools prompts for admin powershell

I'm trying to install windows-build-tools using NPM. I tried it from the command prompt and it told me to use Administrative Powershell. So I opened up a PowerShell instance in admin mode (right click, 'Run as Administrator') and reran the command:
PS C:\Users\me> npm install -g windows-build-tools
The installation failed, and it says Please restart this script from an administrative PowerShell!
How can I install this npm package?
This is not a duplicate of Windows-build-tools installation failed -- that question suggests adding Powershell to the path and I already have Powershell on my path.
I have also tried with the --production flag in addition to the global flag that I had in the above example; same results.
Full output:
PS C:\Users\me> npm install -g windows-build-tools
> windows-build-tools#5.2.2 postinstall C:\Users\me\AppData\Roaming\npm\node_modules\windows-build-tools
> node ./dist/index.js
Downloading python-2.7.15.amd64.msi
[> ] 0.0% (0 B/s)
Downloaded python-2.7.15.amd64.msi. Saved to C:\Users\me\.windows-build-tools\python-2.7.15.amd64.msi.
Downloading vs_BuildTools.exe
[> ] 0.0% (0 B/s)
Downloaded vs_BuildTools.exe. Saved to C:\Users\me\.windows-build-tools\vs_BuildTools.exe.
Starting installation...
Please restart this script from an administrative PowerShell!
The build tools cannot be installed without administrative rights.
To fix, right-click on PowerShell and run "as Administrator".
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! windows-build-tools#5.2.2 postinstall: `node ./dist/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the windows-build-tools#5.2.2 postinstall 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! C:\Users\me\AppData\Roaming\npm-cache\_logs\2019-07-30T20_46_40_244Z-debug.log
Relevant part of the debug log (you can see my PATH in the 4th line; Powershell is at the end):
4102 silly postinstall windows-build-tools#5.2.2
4103 info lifecycle windows-build-tools#5.2.2~postinstall: windows-build-tools#5.2.2
4104 verbose lifecycle windows-build-tools#5.2.2~postinstall: unsafe-perm in lifecycle true
4105 verbose lifecycle windows-build-tools#5.2.2~postinstall: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\me\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\.bin;C:\Users\me\AppData\Roaming\npm\node_modules\.bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\nodejs\;C:\Users\me\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\me\AppData\Local\Programs\Python\Python37-32\;C:\Users\me\AppData\Local\Microsoft\WindowsApps;C:\Users\me\AppData\Local\JetBrains\IntelliJ IDEA 2019.2\bin;C:\Users\me\AppData\Local\Programs\Git\cmd;C:\Users\me\AppData\Roaming\npm;C:\windows\system32\WindowsPowerShell\v1.0
4106 verbose lifecycle windows-build-tools#5.2.2~postinstall: CWD: C:\Users\me\AppData\Roaming\npm\node_modules\windows-build-tools
4107 silly lifecycle windows-build-tools#5.2.2~postinstall: Args: [ '/d /s /c', 'node ./dist/index.js' ]
4108 silly lifecycle windows-build-tools#5.2.2~postinstall: Returned: code: 1 signal: null
4109 info lifecycle windows-build-tools#5.2.2~postinstall: Failed to exec postinstall script
4110 timing action:postinstall Completed in 143406ms
4111 verbose unlock done using C:\Users\me\AppData\Roaming\npm-cache\_locks\staging-a76b9d439c0e45ea.lock for C:\Users\me\AppData\Roaming\npm\node_modules\.staging
4112 timing stage:rollbackFailedOptional Completed in 919ms
4113 timing stage:runTopLevelLifecycles Completed in 152174ms
Node version: 10.16.0
NPM version: 6.9.0
(Yes, I'm very sure I'm running in admin mode; the title bar of my PowerShell instance says Administrator: c:\windows\system32\windowspowershell\v1.0\powershell.exe.)
I am using VS2019 and this is working for me
npm install --global windows-build-tools#4.0.0
I run this command "npm install --global windows-build-tools" using Administrative privileges and it worked for me.
Completely reinstall node with command
npm install reinstall -g
then retry
npm install -g windows-build-tools

CodeBuild failing to run CDK synth

I'm having a problem running cdk synth on codebuild, it just says: You are not authorized to perform this operation.
It's a CDK application to provision some infrastructure using #aws-cdk/app-delivery dependency to create the CI/CD pipeline. The codebuild image I'm using is: aws/codebuild/nodejs:10.1.0
The buildspec.yml is a standard one that app-delivery shares in their readme, just adding --loglevel verbose to have a better understanding of what's happenning
phases:
install:
commands:
# Installs the npm dependencies as defined by the `package.json` file
# present in the root directory of the package
# (`cdk init app --language=typescript` would have created one for you)
- npm install
build:
commands:
# Builds the CDK App so it can be synthesized
- npm run build
# Synthesizes the CDK App and puts the resulting artifacts into `dist`
- npm run cdk synth --loglevel verbose -- -o dist
artifacts:
# The output artifact is all the files in the `dist` directory
base-directory: dist
files: '**/*'
And here are the codebuild logs:
[Container] 2019/06/06 19:20:11 Running command npm run cdk synth --loglevel verbose -- -o dist
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli 'run',
npm verb cli 'cdk',
npm verb cli 'synth',
npm verb cli '--loglevel',
npm verb cli 'verbose',
npm verb cli '--',
npm verb cli '-o',
npm verb cli 'dist' ]
npm info using npm#5.6.0
npm info using node#v10.1.0
npm verb run-script [ 'precdk', 'cdk', 'postcdk' ]
npm info lifecycle dvi-infrastructure-cdk#0.1.0~precdk: dvi-infrastructure-cdk#0.1.0
npm info lifecycle dvi-infrastructure-cdk#0.1.0~cdk: dvi-infrastructure-cdk#0.1.0
> dvi-infrastructure-cdk#0.1.0 cdk /codebuild/output/src891487954/src
> cdk "synth" "-o" "dist"
You are not authorized to perform this operation.
npm verb lifecycle dvi-infrastructure-cdk#0.1.0~cdk: unsafe-perm in lifecycle true
npm verb lifecycle dvi-infrastructure-cdk#0.1.0~cdk: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/codebuild/output/src891487954/src/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
npm verb lifecycle dvi-infrastructure-cdk#0.1.0~cdk: CWD: /codebuild/output/src891487954/src
npm info lifecycle dvi-infrastructure-cdk#0.1.0~cdk: Failed to exec cdk script
npm verb stack Error: dvi-infrastructure-cdk#0.1.0 cdk: `cdk "synth" "-o" "dist"`
npm verb stack Exit status 1
npm verb stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
npm verb stack at EventEmitter.emit (events.js:182:13)
npm verb stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
npm verb stack at ChildProcess.emit (events.js:182:13)
npm verb stack at maybeClose (internal/child_process.js:957:16)
npm verb stack at Process.ChildProcess._handle.onexit (internal/child_process.js:246:5)
npm verb pkgid dvi-infrastructure-cdk#0.1.0
npm verb cwd /codebuild/output/src891487954/src
npm verb Linux 4.14.114-83.126.amzn1.x86_64
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "cdk" "synth" "--loglevel" "verbose" "--" "-o" "dist"
npm verb node v10.1.0
npm verb npm v5.6.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! dvi-infrastructure-cdk#0.1.0 cdk: `cdk "synth" "-o" "dist"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the dvi-infrastructure-cdk#0.1.0 cdk script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 1, true ]
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-06-06T19_20_13_082Z-debug.log
[Container] 2019/06/06 19:20:13 Command did not exit successfully npm run cdk synth --loglevel verbose -- -o dist exit status 1
[Container] 2019/06/06 19:20:13 Phase complete: BUILD State: FAILED
[Container] 2019/06/06 19:20:13 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm run cdk synth --loglevel verbose -- -o dist. Reason: exit status 1
I've been able to check which was the error by running npm run cdk synth -- -v -o dist command in my buildspec.yml. With that I got the following error:
Some context information is missing. Fetching...
Reading AZs for 244496089465:us-west-2
Using default AWS SDK credentials for account 244496089465
You are not authorized to perform this operation.
UnauthorizedOperation: You are not authorized to perform this operation.
at Request.extractError (/codebuild/output/src133069252/src/node_modules/aws-sdk/lib/services/ec2.js:50:35)
at Request.callListeners (/codebuild/output/src133069252/src/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/codebuild/output/src133069252/src/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/codebuild/output/src133069252/src/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/codebuild/output/src133069252/src/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/codebuild/output/src133069252/src/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /codebuild/output/src133069252/src/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/codebuild/output/src133069252/src/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/codebuild/output/src133069252/src/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/codebuild/output/src133069252/src/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
So, by adding the following permission ec2:DescribeAvailabilityZones into the codebuild role solved my problem

How do I publish a private npm package with gitlab ci?

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 ''

Gitlab-ci-multi-runner continues if npm publish fails

I use gitlab-ci-multi-runner to publish our artifact to our own npm registry. This is the .gitlab-ci.yml file:
publish-continuous:
type: publish
script:
- npm install
- npm run test
- npm run build
- npm publish --registry $env:NPM_REGISTRY_URL
Sometimes the npm publish fails. This is the output:
$ npm publish --registry $env:NPM_REGISTRY_URL
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\SomeUser\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "publish" "--registry" "https://ourownregistry"
npm ERR! node v4.2.6
npm ERR! npm v3.6.0
npm ERR! code ENEEDAUTH
I would expect that the gitlab-ci-multi-runner stops because the job fails. But it doesn't! It reports Build succeeded.
Anyone knows how I can make the build fail if npm publish fails?
Fixed it by updating to the latest NPM. v3.8.1 fixed the issue. Now it returns a -1 exit code and the build fails.