简体   繁体   中英

Error - Cannot find module 'broccoli'

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM