Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot find module 'npm'" #20

Closed
timdp opened this issue Jul 14, 2015 · 10 comments
Closed

"Cannot find module 'npm'" #20

timdp opened this issue Jul 14, 2015 · 10 comments

Comments

@timdp
Copy link
Contributor

timdp commented Jul 14, 2015

I use npm@3.1.2. Using grunt-aws-lambda gives me:

Loading "lambda_package.js" tasks...ERROR
>> Error: Cannot find module 'npm'
>>     at Function.Module._resolveFilename (module.js:336:15)
>>     at Function.Module._load (module.js:278:25)
>>     at Module.require (module.js:365:17)
>>     at require (module.js:384:17)
>>     at Object.module.exports (node_modules\grunt-aws-lambda\tasks\lambda_package.js:14:15)

Looks like require('npm') no longer works by default with npm 3.

npm i npm@3.1.2 fixes it, so you can probably just include npm in the dependencies. No idea how you would elegantly pass the version of the globally installed npm though. A postinstall hook would work, I guess.

@Tim-B
Copy link
Owner

Tim-B commented Jul 14, 2015

Hi @timdp, thanks for the report!

Can you confirm you're using the latest version of this plugin (ie. 0.8.0)? npm was added to the devDependencies a few versions back which solved some similar issues a few people were having.

I also installed NPM 3.1.2 and it seems to be working okay for me.

@timdp
Copy link
Contributor Author

timdp commented Jul 14, 2015

Thanks for the quick response!

Won't devDependencies only get installed if I install my own module with --dev? That's not something I'm eager to do.

Is there a reason why it's not a regular dependency?

@Tim-B
Copy link
Owner

Tim-B commented Jul 14, 2015

My understanding is that devDependencies should get installed by a regular npm install unless you add the --production flag.

If you are using the latest version you could try moving it to regular dependencies, I'd be interested to know if that helps.

@timdp
Copy link
Contributor Author

timdp commented Jul 14, 2015

Pretty sure that that's not how it works. Installing devDependencies for all dependencies by default would mean a hell of a lot of modules to install. For example, for every module that depends on PhantomJS for browser testing, you'd then unzip PhantomJS again. Particularly with npm 2's non-flattened node_modules folder, you'd waste a lot of disk space on modules that never get used, since you'd never run the tests for your dependencies; that's the author's job.

I verified this by just running npm init && npm i --save grunt grunt-aws-lambda in a new folder. It created neither node_modules/npm nor node_modules/grunt-aws-lambda/node_modules/npm. With --save-dev rather than --save, I got the same result. The only difference between those two flags is how it updates package.json, I think.

@timdp
Copy link
Contributor Author

timdp commented Jul 14, 2015

Maybe you're getting confused by how npm i works from inside your module's folder? It will install both dependencies and devDependencies for ./package.json, but not for their dependencies.

@Tim-B
Copy link
Owner

Tim-B commented Jul 15, 2015

Yeah you're right, I was thinking of the situation where the module was being installed directly as opposed to being installed as a dependency.

Truth be told I was never able to replicate the issue, however someone submitted a pull request saying adding npm to devDependencies fixed it for them. The change didn't cause any tests to fail and didn't seem to have any side effects so I accepted it.

So does adding npm as a regular dependency help your issue?

@timdp
Copy link
Contributor Author

timdp commented Jul 15, 2015

It most likely would. I'm at work now, but I'll test soon.

@peterfox
Copy link

I had an issue with this on my Mac, just had to add
export NODE_PATH='/usr/local/lib/node_modules'

to my ~/.bash_profile and it worked fine afterwards.

@timdp
Copy link
Contributor Author

timdp commented Jul 23, 2015

That sounds like a different issue to me.

@timdp
Copy link
Contributor Author

timdp commented Jul 27, 2015

Making npm a regular dependency worked for me.

I initially tried with npm@^3.2.0, but that failed. I'll make a new issue for documenting my findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants