npm Gulp dependencies missing, even after running

2019-02-09 20:06发布

问题:

I have a project that uses Gulp. I deployed my project onto my Ubuntu server and now want to compile the assets (which is all my gulpfile does at the moment). Having installed Node and npm I run npm install from my project's root to install the dependencies. The package.json reads as follows:

  ...},
  "devDependencies": {
    "bower": ">=1.3.12",
    "gulp": "^3.8.10",
    "gulp-concat": "^2.4.3",
    "gulp-less": "^2.0.1",
    "gulp-minify-css": "^0.4.3",
    "gulp-notify": "^2.2.0",
    "gulp-rename": "^1.2.0",
    "gulp-uglify": "^1.1.0"
  }...

Upon then inspecting the node_modules folder in my project root I can see directories for each of the dependencies indicating they were installed. However when I run gulp I get npm errors such as the below:

Error: Cannot find module 'through2'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)

These seem to be dependencies of the my project's dependencies (as they are not referenced in my gulpfile), but why hasn't npm installed them?

I can manually install each one as the error arises but I then get another similar error for the next missing dependency.

How can I solve this?

回答1:

The solution was to delete the node_modules folder and rerun npm install.

It looks like the initial install failed partially for some reason.