Error: Cannot find module, despite module installed globally Follow
I am using Intellij Idea and I am trying to run a Node script that uses the Puppeteer module. When I run the script outside of Intellij Idea, it works fine. But when I run it inside, I get the following error:
Error: Cannot find module 'puppeteer'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/myuser/.rvm/gems/ruby-2.1.2@core/bundler/gems/docket-plus-43e0140393ef/lib/data/js/county/practice.js:6:19)
Basically, the script is inside a ruby gem stored somewhere else in filesystem. I run the script from another project. But I set up puppeteer with npm globally:
npm install -g puppeteer
This means that the puppeteer should be found no matter where I run the script. I installed the NodeJS plugin for Intellij Idea and I see puppeteer cited in the preferences:
Yet i continue to get this error. Why can't it find the puppeteer module?
Please sign in to leave a comment.
>This means that the puppeteer should be found no matter where I run the script
No, nothing of the kind. Globally installed modules can't be required from local scripts; the global installation is only used for setting up system-wide available binaries, such as unit test runners or bootstrappers or things like that.
You can use
NODE_PATH
to specify a different location, but note that using it is not recommended:Actually I had to add it to .bash_profile:
export NODE_PATH='/usr/local/lib/node_modules'