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?
I don't think so. I believe the module should be using the prepublish hook instead of postinstall one.
What do you suggest for git dependencies?
"dependencies": {
"something": "github:someone/something#decafbad"
}
This is commonly used when a project needs to depend on a particular git revision of a module with a bugfix that hasn't yet been released.
Being able to do this becomes particularly important when depending on modules with infrequent release cycles. It allows you to fork the buggy project, fix a bug, then add a dependency to your bug-fixed fork.
However, if the buggy module uses gulp this is currently impossible.
To give you a specific example - I'm developing a web app and I want to use my fork of zombie which has some bug fixes.
Unfortunately I can't use it since gulp refuses to run during npm's postinstall hook.
A release branch or tag is usually what I use.
A git branch or tag won't affect this in any way. I think you may have misunderstood what the problem is. Maybe I didn't explain it clearly. To make it more clear, here is how you can reproduce it:
mkdir gulp-issue-1477
cd gulp-issue-1477
npm init -y
npm install --save-dev aslakhellesoy/zombie#fix-npm-source-module
This fails with:
Local gulp not found in node_modules/zombie
Try running: npm install gulp
In case it wasn't clear from my previous messages - I am not an owner of the zombie module - I forked it so I could fix some bugs. I want to depend on that fork while I'm waiting for my bugfixes to be released to npm by the maintainer of the zombie module.
As it stands, gulp cannot be used as an npm postinstall build tool alongside npm modules from git. I think is a severe limitation, especially now that so many modules will need a postinstall to transpile es6.
This wouldn't be a problem if all module maintainers made new npm releases every day, but in reality it can take months, which is why npm lets people pull modules from git.
Please let me know if I have overlooked something obvious.
Correct. This is an npm problem that has come with npm 3. Postinstall should be prepublish and you should commit that build to a different branch or tag and then delete it when a release is made...
Gulp behaves in the same way for both npm3 and npm2 with the example I provided above. Have you considered the possibility that this has nothing to do with npm, but with gulp?
Gulp refuses to run if it isn't found in underneath the current npm module's node_modules directory. What's the rationale behind this decision?
Are you suggesting I commit transpiled es6 code to git to work around this limitation of gulp? Don't you have any suggestions about how to fix this (IMHO, broken) behaviour in gulp?
Support questions should be directed to StackOverflow. If you provide a repro case for this, please add a link here.
This isn't a support request, it is a bug report.
I supplied 4 lines of shell commands above to reproduce the bug.
Please supply a reproduction repo otherwise we need to write this off as a support request.
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?
@aslakhellesoy I ran into the same problem, and I think that the solution might actually be to use a prepublish script, even though the explanation here is quite poor.
I think that what happens when you install a package from git, is this:
npm install is run in the temporary locationprepublish script is run in the temporary locationnode_modules, according to .npmignore or the files property in package.jsonSo, when pulling a git repository you actually do a local publish behind the scenes, to your local node-modules location.
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.
Most helpful comment
I just came across the same issue... I published a node module which has the following entries in
package.json:Unfortunately people, who install my library, get an error during the
postinstallstep becausegulpcannot be found. But I expectednpmto find the local gulp which is declared in my library's development dependencies:Do I need to declare
gulpas usual dependency to usegulp buildin apostinstalltask?