Simon Simon - 1 year ago 72
Git Question

Prepublish not working as expected

I am testing on npm scripts to build my project dependency.

My idea comes from which impressed me by code in repository doesn't mean code in node_modules after

npm install

Below is my testmodule structure


and this is my package.json content

"name": "testmodule",
"version": "1.0.0",
"description": "",
"main": "lib/index.js",
"scripts": {
"build": "babel src/ -d lib/",
"prepublish": "npm run build"
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2"

and this is structure I expect after run
npm install testmodule


which is src folder should not be here.

But after I run
npm install
, it is exactly the same as when I push to my git repository.

Please take note that I am using GitLab in my own server.

So my questions are:

  1. Is there anything that i'm missing to make prepublish run?

  2. Which part of parse-server code makes the src folder and other files not there after install?

Answer Source

How are you running npm install?

According to the documentation on npm scripts, the prepublish script is run "BEFORE the package is published. (Also run on local npm install without any arguments.)". It seems clear that the prepublish script is only run on npm publish or npm install <local directory>.

If you are trying to install directly from your local gitlab server via a URL, this will not work - the script will not be run. The solution would be to install locally unless you're willing to open source your package & push it to the npm repository or pay for a private npm repository. This is what I have done during development of packages before they're ready to be made public.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download