Required package not found


#1

I am following the hacking instruction https://atom.io/docs/v0.196.0/hacking-atom-package-modifying-text
As in the instruction I have "require ‘figlet’ ". Atom won’t find it and I will paste the exception in the end.

  1. I already installed the package ‘figlet’ from within Atom. It shows in my installed package list
  2. I also tried installing from npm
  3. I can use figlet functionality from the command line
  4. In my project I already put the dependencies in package.son as “figlet”: “0.4.0”
  5. In the code I have figlet = require ‘figlet’ as in the instruction
  6. The downloaded figlet library existed under ~/.atom/, while my project is located on ~/Documents/workspace/. Does this matter?
  7. I tried reloading the view and restarting Atom

No matter what I tried, the exception is thrown. Looking for help… The exception is,

Error: Cannot find module ‘figlet’ at Module._resolveFilename (module.js:328:15)
at Function.Module._resolveFilename (/Applications/Atom.app/Contents/Resources/app.asar/src/module-cache.js:383:52)
at Function.Module._load (module.js:270:25)
at Module.require (module.js:357:17)
at require (module.js:376:17)
at Object.module.exports.MyAtomPackage0.toggle (/Users/mountain7cat/Documents/workspace/my-atom-package0/lib/my-atom-package0.coffee:40:16)
at atom-workspace.subscriptions.add.atom.commands.add.my-atom-package0:toggle (/Users/mountain7cat/Documents/workspace/my-atom-package0/lib/my-atom-package0.coffee:17:91)
at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:238:29)
at CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61)
at CommandRegistry.module.exports.CommandRegistry.dispatch (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:153:19)
at EventEmitter. (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:71:30) at emitOne (events.js:77:13)
at EventEmitter.emit (events.js:166:7)


#2

The issue here is that there is as figlet Atom package and a figlet Node module. The one you need to have installed is the Node module. And if you notice the instructions state to add the following to your package.json:

"dependencies": {
  "figlet": "1.0.8"
}

Whereas you state that you declared the dependency as 0.4.0.

To correct the situation:

  1. Correct the package.json dependencies declaration
  2. Open a terminal window
  3. Navigate to the directory where the package.json is
  4. Execute the command apm install

Things should work better after that.


#3

That works! The thing I missed was I did not run “apm install”. Thanks!