2

I'm getting this error and cannot find any way to fix it. It occurs upon trying to execute broccoli build.

Error: Cannot find module 'broccoli' from '/Users/devel/Projects/broccoliTest'
    at Function.module.exports [as sync] (/usr/local/lib/node_modules/broccoli-cli/node_modules/resolve/lib/sync.js:32:11)
    at Object.<anonymous> (/usr/local/lib/node_modules/broccoli-cli/bin/broccoli:7:28)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

I've just installed sudo npm install -g broccoli and sudo npm install -g broccoli-cli. The broccoli executable file is fine, obv:

>which broccoli
/usr/local/bin/broccoli

so it seems that the broccoli module is not correctly installed, although no error occured in the installation process.

ls /usr/local/lib/node_modules/broccoli
CHANGELOG.md    LICENSE     README.md   docs        lib     node_modules    package.json    templates

Any ideas?

Tudor Vintilescu
  • 1,450
  • 2
  • 16
  • 28
  • 1
    To install a package both for command line and for requiring, it has to be [installed both globally and locally](https://www.npmjs.org/doc/files/npm-folders.html) -- "● *Install it **locally** if you're going to `require()` it. ● Install it **globally** if you're going to run it on the command line.*" And, "*local*" means [relative to the script's path](http://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders). – Jonathan Lonowski Jun 15 '14 at 11:35

2 Answers2

4

Globally installed packages aren't made available to require(), by design:

  • Install it locally if you're going to require() it.
  • Install it globally if you're going to run it on the command line.
  • If you need both, then install it in both places, or use npm link.

You'll have to also install it locally, relative to your scripts:

cd /Users/devel/Projects/broccoliTest
npm install broccoli
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199
0

You can execute you command using a relative path like this:

./node_modules/.bin/broccoli build

To avoid that you can use broccoli-cli to take care of figuring out the path for you.

yarn add -D broccoli-cli
npm install --save-dev broccoli-cli

Or you can just install it globally.

givanse
  • 14,503
  • 8
  • 51
  • 75