NPM Package registry does not install correctly global commands

Hello, I published a private NPM package using the GitLab NPM Package Repository, which needs to be scoped.

This package is supposed to add an sspm command available globally to work as a CLI.

When I install it from the repository using npm install -g @{ORG}/{PACKAGE_NAME}, it is correctly added under /usr/local/lib/node_modules/@{ORG}/{PACKAGE_NAME} and the files seems correct, but when I run one of the following commands, the command is not found :

# zsh: command not found: sspm ​
sspm
@{ORG}/sspm
@{ORG}\/sspm

But if I install the package globally using the project path instead of its name, it works (even if when I install it using its name, the files are correctly downloaded)

Here is all I’ve tried until here

npm install -g @{ORG}/{PACKAGE_NAME}
sspm # command not found

npm uninstall -g @{ORG}/{PACKAGE_NAME}

npm install -g ./ # Installing the project from its project directory
sspm # WORKS

Here is my package.json file :

{
  "name": "@{ORG}/{PACKAGE_NAME}",
  "version": "1.0.0",
  "main": "src/index.js",
  "publishConfig": {
    "@{ORG}:registry": "https://gitlab.com/api/v4/projects/.../packages/npm/"
  },
  "bin": {
    "sspm": "./bin/main.js"
  },
  "scripts": {...},
  "repository": {
    "url": "https://gitlab.com/..."
  },
  "bugs": {
    "url": "https://gitlab.com/..."
  },
  "homepage": "https://gitlab.com/...,
  "devDependencies": {...},
  "dependencies": {...}
}

Inspecting the NPM location for commands (found by running npm bin -g) it turns out that there is no symlink created for this package. My NPM config shows that the bin-links is correctly set to true.

I also tried to publish an example public package on npmjs.com using the same package.json syntax, and my command was available globally after the install. When I published the same exact package on the GitLab NPM registry, the command was not found after the installation.

As a workaround, I tried to add a scripts.postinstall entry to my package.json which was supposed to create the missing symlinks for each missing bin. But it turns out that the script is not executed after the installation while the NPM documentation says that it should

So, execpt blaming the GitLab NPM Registry itself, I’m running out of ideas…
Thanks for your help

Hello,
we encountered the exact same issue and followed very similar steps. We also pushed the package to npmjs to try out if this works properly and indeed, the symlinks are created and everything works fine.
The only workaround we found so far was to use an older version of nodejs (14.x).
Thanks,
Eric

Hello @ericdoerheit, I’d be interested to know which version of node and NPM you are using, I’m currently using node.js v14.16.1 and npm v7.10.0 and I am still facing this issue. Thanks for your feedback!

Hello @arthur-eudeline,
I’m using the node:14 docker image for that which has version v14.16.1 installed. npm -v returns 6.14.12. Seems to be an issue with npm then?
Best,
Eric

@ericdoerheit Yes, it seems definitly linked to NPM because node.js does not interfere that much with the packages installation process.

I just tried to downgrade my version of NPM to 6.14.12 and it works! (to anyone who wants to downgrade npm, just run npm install -g npm @{VERSION})

In fact, when I downgraded to NPM 6 and tried to install the package globally, the postinstall script has been triggered (which was a good first improvement). So I just removed my custom script.postinstall entry of my package.json, publish it to the GitLab NPM registry and then installed my package globally and my command is now available.

Thanks @ericdoerheit for your leads!