question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Depending on module with postinstall script using gulp broken on npm 3

See original GitHub issue

I’m developing a node app (let’s call it foo) that depends on another npm module (let’s call it bar) that has "postinstall": "gulp build" (to run babel over some es6 code). The bar module also has a devDependency on gulp to make sure people can install the module even if they don’t have gulp installed globally.

When I npm install in foo, the installation of the bar module fails with:

Local gulp not found in /path-to/foo/node_modules/bar
Try running: npm install gulp

This is an error message from gulp, not npm. In fact, gulp has some logic to check whether gulp is installed locally in the module depending on it (in this case, /path-to/foo/node_modules/bar/node_modules/gulp).

Since npm 3 installs all modules flat, the gulp module ends up underneath foo, not bar, causing the gulp cli to exit with this error.

Is there any way around this?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
bennycodecommented, Jul 4, 2016

I just came across the same issue… I published a node module which has the following entries in package.json:

"scripts": {
  "postinstall": "gulp build",
  "test": "gulp test"
}

Unfortunately people, who install my library, get an error during the postinstall step because gulp cannot be found. But I expected npm to find the local gulp which is declared in my library’s development dependencies:

"devDependencies": {  
  "gulp": "^3.9.1",
  ...
}

Do I need to declare gulp as usual dependency to use gulp build in a postinstall task?

1reaction
BrunoZellcommented, Sep 3, 2018

As of npm@5 the script prepublish is deprecated. You can use prepare instead. Make sure to add gulp-cli to your devDependencies so that it is not required as a global module.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm install: Failed at the node-sass@3.13.1 postinstall script
I think this is happening because you're missing the node-sass module. Try the following and rerun your build script and see if this ......
Read more >
gulp-typescript - npm
gulp -typescript. A gulp plugin for handling TypeScript compilation workflow. The plugin exposes TypeScript's compiler options to gulp using ...
Read more >
Why npm Scripts? - CSS-Tricks
I've started using npm scripts in my projects for about the last six months. Before that, I used Gulp and before that, Grunt....
Read more >
Fixing your NPM Installation - Hackers and Slackers
Why does this happen? Because by default, the post-install scripts attempt to run as the current user. Since the current user doesn't have...
Read more >
Trouble performing npm install in Basic Gulp Housekeeping
It seems that npm cannot install the appropriate versions of the modules and ... /gulp-phpspec/node_modules/expect > node npm-scripts/postinstall.js npm ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found