-
Notifications
You must be signed in to change notification settings - Fork 3k
NPM "lifecycle" scripts order: install
/postinstall
scripts being run before all dependencies are finished installing
#5001
Comments
Can you update to 1.4.6 and check to see if it's still occurring? |
@shindakun: Thanks for the suggestion. Still occurring in |
Alternatively: is there any way to install all dependencies (a la |
BTW: Just a hunch but... I suspect this may have something to do with installing dependencies that do not install synchronously (e.g. they have their own Ideally, the NPM |
What do you mean by "asynchronously"? Can you give us some concrete samples of what you're doing? |
@timoxley: I'll try to make a test project for you. |
OK, I seem to have been wrong about the asynchronousity being the issue. Rather, it seems like it has to do with a dependency's dependency's dependency (which is also a direct dependency of the main module) not being fully installed before the dependency's Logical dependency tree:
Physical dependency tree after installation is complete:
Diff: The Problem: The Fix:
Short-Term Workarounds:
|
Most Successful Short-Term Workaround:
|
This seems to be a long-standing issue described in #1341 (comment). |
Another generic workaround that would probably work for most people's use cases: "preinstall": "npm install --ignore-scripts" Or just manually running:
...instead of a normal, standalone |
@JamesMGreene An excellent workaround! Thank you. |
@JamesMGreene That doesn't work for me.
This is something really simple. Not sure why a fix hasn't been proposed yet. |
Looks like the forthcoming multi-stage install (#5919) strategy should resolve this. |
Closing this as this is being fixed in #6926 |
The workaround "buildDependencies": {
"depName": "~v1.x"
},
"scripts": {
"preinstall": "node preinstall.js",
"postinstall": "someUsesDepName_v1.x"
} File var npm = require("npm");
var conf = require("./package.json");
var deps = conf.buildDependencies;
var args = [];
Object.keys(deps).forEach(function (name) {
args.push(name + "@" + deps[name]);
});
npm.load(conf, function (e) {
if (e) return console.error(e);
npm.commands.install(args, function (e) {
if (e) return console.error(e);
console.info("Installed npm modules: ", args);
});
}); It definitely works... |
@misak113 nice suggestion. Thanks. However, in my case |
In my version of node.js (v0.10.25) you can have global module required in your app like local. I don't know if it can be required in earlier version. |
Thanks for the answer. On my machine to use |
Maybe it should be in EnvVar NODE_PATH=/usr/lib/node_modules on some OS (Win etc.) http://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package #2076 http://stackoverflow.com/questions/12594541/npm-global-install-cannot-find-module |
Hm ... In my case I have a "postinstall": "node ./Gulpfile.js make" And then in my if(process.argv && process.argv[2] === 'make') {
var deps = [
'gulp', 'gulp-rename', 'gulp-browserify', 'gulp-plumber',
'gulp-util', 'gulp-uglify', 'ractive', 'gulp-tap'
], index = 0;
(function doWeHaveAllDeps() {
if(index === deps.length) {
gulp.start('make');
return;
} else if(isModuleExists(deps[index])) {
index += 1;
doWeHaveAllDeps();
} else {
setTimeout(doWeHaveAllDeps, 500);
}
})();
};
function isModuleExists( name ) {
try { return !!require.resolve(name); }
catch( e ) { return false }
} |
I've encountered some problems with a module of my that has an
install
script: it seems that the script is run before all of the module's dependencies (devDependencies?) are finished installing. This seems like a bug.This also happens even if I update the "package.json" to execute it during the
postinstall
phase instead.The text was updated successfully, but these errors were encountered: