Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Npm install from repo not running `prepare`

Tags:

I have an npm package for common components hosted on an internal git server. For some reason when I call npm install in another project I want to consume this in it will not run the prepare hook. Obviously, this does not work since the npm package needs a /dist folder in node_modules to be able to consume the package.

I have already tried things such as using the deprecated prepublish hook and even that does not get called. I also tried to do postinstall to see if I could build after install, while that hook did get called it failed because the devDependencies were not installed

package.json

{   "name": "common-components",   "version": "0.1.0",   "scripts": {     "prepare": "npm run build",     "build": "ng build",     ...   },   "private": true,   "dependencies": {     ...   },   "devDependencies": {     ...   }, } 

command being used for install

npm install --save git+ssh://{URL-to-common-components-repo}} 

I have read through the npm-scripts documentation https://docs.npmjs.com/misc/scripts thoroughly and it seems like they insist that prepare hook should always be called for this exact use-case

Updated 5/6/2019

Just as a note I found this bug on NPM community https://npm.community/t/using-npm-ci-does-not-run-prepare-script-for-git-modules/632/4.

I am using npm 6.4.1 which should work according to the bug

like image 690
Midevilworm Avatar asked May 06 '19 19:05

Midevilworm


1 Answers

One thing to check that hit me on a package recently - if there is a .gitignore and not .npmignore npm may be ignoring your /dist folder. Adding an empty .npmignore worked in this case.

"If there’s no .npmignore file, but there is a .gitignore file, then npm will ignore the stuff matched by the .gitignore file. If you want to include something that is excluded by your .gitignore file, you can create an empty .npmignore file to override it."

from https://docs.npmjs.com/misc/developers

like image 157
FiveOFive Avatar answered Nov 27 '22 10:11

FiveOFive