Npm install doesn't seem to get all the dependencies

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 in the repository and ran the automatically generated node app.js This worked, but when I used curl http://localhost:port , I got the error "Could not find syntax parser module." I ran npm install character-parser and then got "Can't find modular transformers." This happened several more times, but after I installed them all, the application started working.

I thought npm install was supposed to relay dependencies. This also bothers me, because I obviously want package.json be used when deploying the application.

+7
npm ubuntu
source share
3 answers

Here is just a script to collect 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 result is as follows:

 "progress": "0.1.0", "request": "2.11.4", 

If you forget to remove the comma from the last entry, you can copy and paste the result.

+2
source share

I got this exact error while I installed npm for https://github.com/HenrikJoreteg/humanjs-sample-app/

I am on a Windows computer, so I suspected that this was a problem with the odd restrictions that Windows has on the number of characters in the file path.

I solved this by shortening my base path to the three-character folder name in my root (in this case, going from C: \ projects \ humanjs-sample-app to C: \ hjs). When I restarted npm everything works. I am not satisfied with this resolution. I don’t need to worry that my base path is too long. This is one of the reasons that people often do not do node development on Windows machines.

An alternative solution should be developed on Linux or Mac, if you have not already done so. This is probably my long term strategy.

+1
source share

When you run npm install <name-of-package> , it will install the package in your node_modules folder, but will not add it as a dependency. To install a package and save it as a dependency in package.json , you should use the --save flag --save this:

npm install <name-of-package> --save

The npm documentation contains additional information about additional flags that can be used, for example, the --save-dev flag to save development dependencies and --save-optional to save additional dependencies with your package.json .

-one
source share

All Articles