Skip to content

"Cannot find module 'npm'" #20

Closed
Closed

Description

@timdp

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.

Activity

  1. Tim-B commented on Jul 14, 2015

    @Tim-B
    Owner

    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.

  2. timdp commented on Jul 14, 2015

    @timdp
    Author

    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?

  3. Tim-B commented on Jul 14, 2015

    @Tim-B
    Owner

    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.

  4. timdp commented on Jul 14, 2015

    @timdp
    Author

    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.

  5. timdp commented on Jul 14, 2015

    @timdp
    Author

    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.

  6. Tim-B commented on Jul 15, 2015

    @Tim-B
    Owner

    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?

  7. timdp commented on Jul 15, 2015

    @timdp
    Author

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

  8. peterfox commented on Jul 22, 2015

    @peterfox

    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.

  9. timdp commented on Jul 23, 2015

    @timdp
    Author

    That sounds like a different issue to me.

  10. timdp commented on Jul 27, 2015

    @timdp
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions