My package.json
looks like this (name/description/etc. omitted).
{
"dependencies": {
"express": "3.3.4",
"jade": "0.34.x",
"mongoose": "3.6.x"
},
"devDependencies": {
"vows": "0.7.x"
}
}
I used express
on the repository and ran the auto-generated node app.js
. This worked, but when I used curl http://localhost:port
I got the error "Cannot find module character-parser." I ran npm install character-parser
and then I got "Cannot find module transformers." This happened a few more times, but after I installed all of them the app started working.
I thought that npm install
was supposed to install dependencies recursively. This also worries me because I obviously want the package.json
to be usable when the app is deployed.
By default, npm install will install all modules listed as dependencies in package.
Solution 1: Ignore the peerDependencies The easiest way to fix the issue is to pass an additional parameter –legacy-peer-deps to npm install. The --legacy-peer-deps tells the npm to ignore the peer dependencies and continue the installation of the package.
Here's a simple script to collect the dependencies in ./node_modules:
var fs = require("fs");
function main() {
fs.readdir("./node_modules", function (err, dirs) {
if (err) {
console.log(err);
return;
}
dirs.forEach(function(dir){
if (dir.indexOf(".") !== 0) {
var packageJsonFile = "./node_modules/" + dir + "/package.json";
if (fs.existsSync(packageJsonFile)) {
fs.readFile(packageJsonFile, function (err, data) {
if (err) {
console.log(err);
}
else {
var json = JSON.parse(data);
console.log('"'+json.name+'": "' + json.version + '",');
}
});
}
}
});
});
}
For one project I'm working on, the output looks like this:
"progress": "0.1.0",
"request": "2.11.4",
If you remember to remove the comma from the last entry, you can copy and paste the output.
I got this exact error while I was npm installing for https://github.com/HenrikJoreteg/humanjs-sample-app/
I'm on a Windows machine, so I suspected that it was an issue with the odd restrictions that Windows has on the number of characters in a file path.
I resolved this by shorting my base path to a three character folder name in my root (in this case going from C:\projects\humanjs-sample-app to C:\hjs). When I re-ran npm install everything worked. I'm not happy with that resolution. I shouldn't have to worry about my base path name being too long. This is one of the reasons that people often don't do node development on Windows machines.
An alternate resolution is to develop on Linux or Mac, if you aren't already. That's probably my long term strategy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With