andthereitgoes
andthereitgoes

Reputation: 889

Publishing a Node module using NPM in Gitlab-ci doesn't work

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 [email protected]~prepublish: cannot run in wd %s %s (wd=%s) [email protected] 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 [email protected]: 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.

Upvotes: 4

Views: 3791

Answers (1)

joki
joki

Reputation: 6879

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.

Upvotes: 10

Related Questions