Exception when activating empty activate


#1

This code throws this exception. I’m baffled. I started with more code, then tried with just the console.log, and then tried this empty one.

# SubAtom = require 'sub-atom'

module.exports = 
class DragDropText
  activate: ->
    # console.log 'activate'
    # @subs = new SubAtom

Failed to activate package named 'drag-drop-text' TypeError: undefined is not a function
  at Package.module.exports.Package.activateNow (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\package.js:235:27)
  at C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\package.js:221:28
  at Package.module.exports.Package.measure (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\package.js:167:15)
  at Package.module.exports.Package.activate (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\package.js:215:14)
  at PackageManager.module.exports.PackageManager.activatePackage (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\package-manager.js:464:21)
  at C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\package-manager.js:445:29
  at Config.module.exports.Config.transact (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\config.js:350:16)
  at PackageManager.module.exports.PackageManager.activatePackages (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\package-manager.js:439:19)
  at PackageManager.module.exports.PackageManager.activate (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\package-manager.js:422:46)
  at Atom.module.exports.Atom.startEditorWindow (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\atom.js:620:21)
  at Object.<anonymous> (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\window-bootstrap.js:12:8)
  at Object.<anonymous> (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\window-bootstrap.js:23:4)
  at Module._compile (module.js:475:26)
  at Object.loadFile [as .js] (C:\Users\Administrator\AppData\Local\atom\app-0.182.0\resources\app\src\6to5.js:138:21)
  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 window.onload (file:///C:/Users/Administrator/AppData/Local/atom/app-0.182.0/resources/app/static/index.js:52:25)

#2

The standard pattern for the “main” or “index” file for Atom packages is this:

module.exports =
  activate: ->
    # Some stuff

  deactivate: ->
    # Some other stuff

Which equates to exporting an object instance. What you’re exporting there is a class. If you want to name your “main” object class you can do something like this:

class DragDropText
  activate: ->
    # Do something

  deactivate: ->
    # Do something else

module.exports = new DragDropText

which exports an instance of the class you’ve created.

(I use this pattern in my bug-report package here.)