npm install not installing module devDependecies of a submodule - node.js

So we have a web application project. Let's call it MainProject. We have other modules that we made. Let's call it ChildProject. The ChildProject's package.json has devDependcies entries.
"devDependencies": {
"some-3rd-party-module": "^1.0.0"
}
So I run npm install in MainProject. However, some-3rd-party-module doesn't get installed because when I run npm start, it shows an error. The error looks like this
module.js:340
throw err;
^
Error: Cannot find module 'some-3rd-party-module'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
What are we doing wrong?

devDependencies are the dependencies needed only while developing the module, like testing frameworks. They won't be installed when you're including the module in another project.
If your module ChildProject depends on some-3rd-party-module that should be listed under its dependencies not devDependencies.

Related

node express module not found when installed globally

my node app directory sits at /usr/node/express-test/app.js
I followed this thread to set up my environment so that I can have a freelancer come in and install npm packages globally on our server without having to have access to sudo.
How to npm install globally without root
I've checked my NODE_PATH... looks okay to me.
echo $NODE_PATH
/usr/node/.npm-packages/lib/node_modules
However, the error I see when I try to run my app.js appears to be that it cannot find my globally installed express module
app.js
/usr/node/express-test# node app.js
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'express'
Require stack:
- /usr/node/express-test/app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/usr/node/express-test/app.js:2:15)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/usr/node/express-test/app.js' ]
}
Ideas to what the problem may be please?
My suggestions on this:
First of all, do not install express or any other packages as global put packages in the package.json and run npm install or do npm install --save express to save the packages to local node_modules and list it in package.json, track that package.json & package-lock.json in git so that it can be used in other places, this way if you shift to some new VM you don't need to install packages as global again, you can just do npm install or better npm ci and it's all work.
Secondly, if you still want to use global packages go to /usr/node/.npm-packages/lib/node_modules and see if you can find express folder there

Getting "Cannot find module 'request-json/node_modules/request'" while trying to run mocha tests

I am trying to run mocha tests as below:
mocha test\myTest.js
However I get below error:
module.js:340
throw err;
^
Error: Cannot find module 'request-json/node_modules/request'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:289:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)....
I explicitly tried adding npm dependencies request and request-json but it did not help. Am I missing something?
For some reason the latest version of the npm module request-json was not installing it required dependencies. I manually did a npm install inside this module and that solved the issue.

Deploy KeystoneJS site without generator-keystone

I have the entire set of sources of a site, based on KeystoneJS. I tried to deploy it to my laptop (without generator-keystone, because all required files are already generated), but even after
npm install
I got errors, like:
> node keystone.js
module.js:327
throw err;
^
Error: Cannot find module 'methods'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
I have installed methods, and now it requires utils-merge.
How I could install ALL required packages???
ENV: Ubuntu 14.04
npm install -g npm
The reason was in outdated NPM.

Node.js and Grunt install on Windows

I have Node.js installed and I have ran npm install -g grunt-cli I have cd to the directory of the app I am to work on and followed the instructions here. When I run grunt in my cmd it returns
module.js:340
throw err;
^
Error: Cannot find module '\\Server\username$\Redirected\AppData\npm\AppData\npm\node_modules\grunt-cli'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
I really am not sure why its trying to read from \AppData\npm\AppData\npm\ as I haven't made any changes and I don't know how to change the grunt location
But when I use npm install -g grunt-cli it downloads and installs to the following \\Server\username$\Redirected\AppData\npm\node_modules\grunt-cli
You need to change the global install directory.
Try this ..
In C:\Users{username}\, create .npmrc file with contents:
prefix = "C:\\Users\\{username}\\AppData\\Roaming\\npm"
This is discussed more fully here:
Change default global installation directory for node.js modules in Windows?

nodejs on windows: nmp install does not download modules

I have installed a 64bit nodejs on my windows7 (classical installation, no errors during installation)
I created a simple package.json
{
"name":"chat",
"version":"0.0.1",
"private":"true",
"dependecies":{
"socket.io":"0.9.16",
"express":"3.1.0",
}
}
then install it with
npm install
and... Nothing: no packages are downloaded !
(if I make an error in the package.json, I got errors messages at npm install)
Everything seems to be fine, except that npm install does not install anything.
and of course when trying to luch a nodejs project, I got:
Error: Cannot find module 'express'
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)
You have a typo in your package.json, it should be "dependencies".
Make sure to generate your package.json with npm init, so to avoid this kind of problems.

Resources