Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

npm ci & dependencies over SSH: build missing or scripts not being executed

Robin Lankhorst March 3, 2020

We want to use Bitbucket Pipelines to test & deploy a project of ours. Two dependencies to the project are private Git repositories also on Bitbucket, formatted using the following notation in package.json:

"@namespace/repository": "bitbucket:[owner]\[repository].git#[commit-hash]"

The pipelines YML file, in a simplified form, contains the following data:

image: node:13.8.0

pipelines:
default:
- step:
caches:
- node
script:
- npm ci -dd
- find node_modules/@namespace/repository

The 'npm ci' command does succeed, but the namespace/repository's prepare script is seemingly not executed, as the 'find' script will only report the existance of the package.json and README.md file (and those are included by default).

The scripts that exist in this dependency repo:

"scripts": {
"analyze": "node ./scripts/analyze.js",
"start": "start-storybook -p 9009 -s public",
"build": "build-storybook -s public",
"build:lib": "node ./scripts/export-gen.js && webpack && node ./scripts/clean.js",
"prepare": "npm run build:lib"
}
}

The 'prepare' script (and therefore 'build:lib') makes sure that the library is built and useable as a module. Executing the same 'npm run build:lib' on (post)install collides with missing dependencies.

What are we doing wrong?

1 answer

1 accepted

5 votes
Answer accepted
Robin Lankhorst March 6, 2020

We solved our issue after extensive testing, where we realised the issue was a result of the misbehaving combination of NPM and Docker.

We updated our bitbucket-pipelines.yml file to include the following line:

image: node:13.8.0

pipelines:
default:
- step:
script:
- npm config set unsafe-perm true
- npm ci -dd
- find node_modules/@namespace/repository

This relates to this issue with npm, and running 'prepare' scripts when the user is 'root' (which is the case with Docker containers). Also, running on older versions of the Node image might still yield the same failing result.

(Also, don't use the cache 'node' for 'npm ci' contexts, as it will always remove node_modules if it already exists.)

Lester Antonio Gonzalez Gutierrez September 30, 2020

Amazing you save my day,I was trying to solve the same problem for 72 hours testing everything without any results, the funniest thing that in all local environments it worked properly

Thanks !!!!!!

Matt Todd November 9, 2020

Worked like a charm, saved me a few hours of head banging 👊

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events