You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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.
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?
Activity
Tim-B commentedon 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
devDependenciesa 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 commentedon Jul 14, 2015
Thanks for the quick response!
Won't
devDependenciesonly 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 commentedon Jul 14, 2015
My understanding is that
devDependenciesshould get installed by a regularnpm installunless you add the--productionflag.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 commentedon 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-lambdain a new folder. It created neither node_modules/npm nor node_modules/grunt-aws-lambda/node_modules/npm. With--save-devrather than--save, I got the same result. The only difference between those two flags is how it updates package.json, I think.timdp commentedon Jul 14, 2015
Maybe you're getting confused by how
npm iworks from inside your module's folder? It will install both dependencies and devDependencies for ./package.json, but not for their dependencies.Tim-B commentedon 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
devDependenciesfixed 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 commentedon Jul 15, 2015
It most likely would. I'm at work now, but I'll test soon.
peterfox commentedon Jul 22, 2015
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 commentedon Jul 23, 2015
That sounds like a different issue to me.
timdp commentedon 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.