4

I am using gitlab-ci to for my CI/CD to publish a NPM module to a registry. Following is my gitlab-ci.yml file

image: docker:latest

variables:
  DOCKER_DRIVER: overlay2

services:
- docker:dind

cache:
  untracked: true
  key: "$CI_COMMIT_REF_NAME"
  paths:
    - node_modules/
stages:
    - setup

job-setup:
   stage: setup
   tags:
    - angular
   image: node:alpine
   except: 
    - tags
   script:
     - npm set registry https://registry.npmjs.org
     - npm i
     - cp .npmrc ~/.npmrc
     - npm publish --registry https://registry.npmjs.org

I get the following warning messages on the publish command. The module gets published but the /dist folder within the module is missing.

npm WARN prepublish-on-install As of npm@5, `prepublish` scripts are deprecated.
npm WARN prepublish-on-install Use `prepare` for build steps and `prepublishOnly` for upload-only.
npm WARN prepublish-on-install See the deprecation note in `npm help scripts` for more information.
npm WARN lifecycle my_npm_module@1.1.1~prepublish: cannot run in wd %s %s (wd=%s) my_npm_module@1.1.1 npm run build /builds/code/my_npm_module
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

NPM is having issues with running in the 'working directory' (wd) and I am not sure how to solve it. I am running gitlab-ci on Centos.

andthereitgoes
  • 819
  • 2
  • 10
  • 24

1 Answers1

10

npm is refusing to run the build scripts from your package.json because it's running as root. Add

echo "unsafe-perm = true" >> ~/.npmrc

to your gitlab-ci.yml script before invoking npm.

joki
  • 6,619
  • 2
  • 22
  • 30
  • This solved my problem. I did not know that the gitlab runner was executing these commands as root, and the error message is not helpful: `~prepublish: cannot run in wd %s %s (wd=%s)` – Tom Jan 30 '19 at 20:15
  • This didn't work for me, most probably because my `~/.npmrc` (which is copied from an injected variable to whose content I don't have easy access right now) doesn't contain an EOL at the end. So `npm config set unsafe-perm true` instead of the `echo ...` did the job perfectly. – Antonio Pérez Nov 25 '21 at 16:26