Cannot find module 'atom-space-pen-views'


#1

I am new to atom and wanted to try my hand at writing a plugin package.
I copied the following code snippet from the ‘styleguide’ but ended but getting an error

{SelectListView, $$} = require 'atom-space-pen-views'

module.exports =
class ExampleSelectListView extends SelectListView
  initialize: (@listOfItems) ->
    super
    @setItems(@listOfItems)

  viewForItem: (item) ->
    $$ -> @li(item)

  cancel: ->
    console.log("cancelled")

  confirmed: (item) ->
    console.log("confirmed", item)

I got this stacktrace:

Cannot find module 'atom-space-pen-views'Hide Stack TraceError: Cannot find module 'atom-space-pen-views'  at Module._resolveFilename (module.js:351:15)  at Function.Module._resolveFilename (/usr/share/atom/resources/app/src/module-cache.js:383:52)  at Function.Module._load (module.js:293:25)  at Module.require (module.js:380:17)  at require (module.js:399:17)  at Object.<anonymous> (/home/rahul/github/test/lib/test-view.coffee:1:24)  at Object.<anonymous> (/home/rahul/github/test/lib/test-view.coffee:1:1)  at Module._compile (module.js:475:26)  at Object.requireCoffeeScript (/usr/share/atom/resources/app/node_modules/coffee-cash/lib/coffee-cash.js:85:19)  at Module.load (module.js:370:32)  at Function.Module._load (module.js:325:12)  at Module.require (module.js:380:17)  at require (module.js:399:17)  at Object.<anonymous> (/home/rahul/github/test/lib/test.coffee:1:12)  at Object.<anonymous> (/home/rahul/github/test/lib/test.coffee:1:1)  at Module._compile (module.js:475:26)  at Object.requireCoffeeScript (/usr/share/atom/resources/app/node_modules/coffee-cash/lib/coffee-cash.js:85:19)  at Module.load (module.js:370:32)  at Function.Module._load (module.js:325:12)

#2

Have you specified atom-space-pen-views as a dependency in your package.json file? You need to do that and then do an npm install or apm install to actually install the module.


#3

Thanks. That worked


#4

I’d recommend apm install since with Atom packages I believe there is some extra caching that happens. Also, over time what apm install and npm install do may diverge … and you want to be on the correct side of that change.


#5

Also because some modules must be compiled when installed, and apm uses Atom’s (chromium’s?) V8 header files instead of Node’s.


#6

Running package dependencies update also seems to work,