• Skip to main content
  • Select language
  • Skip to search
MDN Web Docs
  • Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs / DOM
    • WebExtensions
    • MathML
  • References & Guides
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
Add-ons
  1. MDN
  2. Mozilla
  3. Add-ons
  4. Add-on SDK
  5. Tools
  6. cfx to jpm

cfx to jpm

In This Article
  1. Installation
  2. Activation
  3. Add-on incompatibilities
    1. Add-on ID
      1. ID handling with cfx
      2. ID handling with jpm
      3. What you need to do
    2. Entry point
    3. Loading modules
      1. Requiring local modules
      2. Requiring modules from test code
    4. Third-party modules
    5. Mobile development
  4. Commands and command options
    1. Permanently removed commands
    2. Permanently removed options
  5. Package.json fields
    1. Permanently removed fields
  6. Package.json escaping

Add-ons using the techniques described in this document are considered a legacy technology in Firefox. Don't use these techniques to develop new add-ons. Use WebExtensions instead. If you maintain an add-on which uses the techniques described here, consider migrating it to use WebExtensions.

From Firefox 53 onwards, no new legacy add-ons will be accepted on addons.mozilla.org (AMO).

From Firefox 57 onwards, WebExtensions will be the only supported extension type, and Firefox will not load other types.

Even before Firefox 57, changes coming up in the Firefox platform will break many legacy extensions. These changes include multiprocess Firefox (e10s), sandboxing, and multiple content processes. Legacy extensions that are affected by these changes should migrate to WebExtensions if they can. See the "Compatibility Milestones" document for more.

A wiki page containing resources, migration paths, office hours, and more, is available to help developers transition to the new technologies.

The Add-on SDK includes a command-line tool that you use to initialize, run, test, and package add-ons. The current tool is called jpm, and is based on Node.js. It replaces the old cfx tool.

You can use jpm from Firefox 38 onwards.

This article highlights the main differences between cfx and jpm.

A guide to working with jpm if you're already familiar with cfx.

Installation

cfx is Python-based and is distributed as a zip file. jpm is Node-js-based and is distributed through npm. So for jpm you don't need Python, but you do need npm.

To get new updates of cfx you download and extract a new zip file, while to get the new version of jpm, use npm update.

For jpm installation instructions, see the Installation section in the jpm reference.

Activation

You need to call cfx activate before you can use cfx, and this only works in the current command shell: if you open a new shell you have to call activate again.

With jpm, you don't need to activate. Once it's installed, you can just use it.

Add-on incompatibilities

In most respects, add-ons created with cfx will work fine with jpm. However, there are a few differences you have to know about.

Add-on ID

The add-on ID is a unique identifier for your add-on. In a built XPI, it's the ID field in the add-on's Install Manifest (install.rdf) file.

The ID is used for a variety of purposes. For example: addons.mozilla.org uses it to distinguish between new add-ons and updates to existing add-ons, and the simple-storage module uses it to figure out which stored data belongs to which add-on.

ID handling with cfx

When you use cfx, the ID is taken from the id field in the add-on's package.json file.  You can edit this file to create your own ID, but if you don't, cfx will generate one for you, which will look something like "jid1-F3BoogbjQJE67A". Add-on IDs need to be one of two types: a GUID or a string that includes an "@" symbol. The SDK expects the latter format, and if the ID in package.json doesn't contain "@", then cfx xpi will append "@jetpack" to the package.json field, and make that the add-on ID.

So: if you never did anything with IDs when using cfx, then the value in your add-on's package.json will be something like "jid1-F3BoogbjQJE67A", and the corresponding ID in the install.rdf will be "jid1-F3BoogbjQJE67A@jetpack".

ID handling with jpm

When you create an XPI with jpm xpi:

  • if the package.json does not include an id field, then the ID written into the install.rdf is the value of the name field prepended with "@".
  • if the package.json does include an id field, and it contains "@", then this is written into the install.rdf as the add-on ID.
  • if the package.json does include an id field, and it does not contain "@", then jpm xpi raises an error and the XPI will not be built.

What you need to do

All this means that: if your package.json contains an id field, and its value does not contain "@", then you must append "@jetpack" to it when switching to jpm.

If you do this, the add-on's ID will be the same as it was when you were using cfx.

Entry point

The add-on's entry point is the file that's executed when the add-on needs to initialize itself: for example, when Firefox starts, or when the add-on's installed, enabled, or upgraded. With cfx, this defaults to "lib/main.js", although it can be set to a different file using the main field in package.json.

In jpm, the entry point defaults to "index.js". So when switching over to jpm:

  • either rename your "main.js" to "index.js" and move it from "lib" to the top level
  • or add a main field to package.json with the value "lib/main.js".

Loading modules

The jpm tool uses the same logic as Node.js to determine how to resolve the argument to require(). In most respects this is the same as the old cfx logic. However there are a few differences, because old compatibility shims have been removed.

Requiring local modules

Suppose your add-on is structured into separate modules:

  • my-addon
    • lib
      • main.js
      • utils.js

When you want to use the "utils" module in "main.js", you should use a path relative to "main.js", and prefix the path with "./" to indicate that it's a relative path:

var utils = require("./utils");

However, with cfx you are also allowed to omit the "./":

var utils = require("utils"); // this will not work with jpm!

This second form will not work with jpm.

Requiring modules from test code

Similarly, suppose you've written some tests for your add-on:

  • my-addon
    • lib
      • my-addon.js
    • test
      • test-my-addon-js

With cfx, code inside "test-my-addon.js" can import "my-addon.js" using a statement like this:

var my_addon = require("my-addon"); // this will not work with jpm!

With jpm, you must specify the path to "my-addon" explicitly, using a relative path:

var my_addon = require("../lib/my-addon");

Third-party modules

The SDK has always supported third-party modules: developers can write their own modules that extend the SDK's APIs or add new APIs, and other add-on developers can make use of these modules in the same way that they use the SDK's built-in modules.

In jpm the old way to use third-party modules no longer works. Instead, jpm expects third-party modules to be hosted on npm, and you can use them by installing them from npm into your add-on's directory tree, then requiring them. See the tutorial on using third-party modules with jpm.

Mobile development

jpm does not support the "--force-mobile" option, instead you will need to define engines in package.json and add "fennec" there.

There is a known bug in simple options handling which may require the workaround described in https://bug635044.bugzilla.mozilla.org/show_bug.cgi?id=1243467

Commands and command options

Permanently removed commands

jpm has dropped support for all the "Internal" cfx commands.

Permanently removed options

jpm has dropped support for:

--extra-packages
--use-config
--package-path
--pkgdir
--no-strip-xpi
--harness-option
--manifest-overload
--output-file
--templatedir
--keydir
--profiledir
--overload-modules
--static-args
--app
--no-run
--addons
--e10s
--logfile
--dependencies
--force-mobile
--test-runner-pkg

Instead of --profiledir and --overload-modules, use --profile and --overload.

Instead of using --force-mobile, explicitly add fennec to engines section of your package.json.

Package.json fields

Many package.json fields are implicit commands to cfx. In jpm, we've removed support for some of these fields, and are still working on supporting some others.

Permanently removed fields

  • data
  • fullName - use title instead
  • lib
  • packages
  • tests
  • icon64

Package.json escaping

Where with cfx you might have had to escape with 2 upto 3 backslashes ( \ ), jpm only needs one now.

 

Document Tags and Contributors

Tags: 
  • add-on
  • CFX
  • JPM
  • SDK
 Contributors to this page: wbamberg, rgh36167, jmozmoz, jsantell, e-motiv, evold
 Last updated by: wbamberg, Dec 1, 2016, 10:47:58 AM
See also
  1. WebExtensions
  2. Getting started
    1. What are WebExtensions?
    2. Your first WebExtension
    3. Your second WebExtension
    4. Anatomy of a WebExtension
    5. Example WebExtensions
  3. How to
    1. Intercept HTTP requests
    2. Modify a web page
    3. Add a button to the toolbar
    4. Implement a settings page
  4. Concepts
    1. Using the JavaScript APIs
    2. User interface components
    3. Content scripts
    4. Match patterns
    5. Internationalization
    6. Content Security Policy
    7. Native messaging
  5. Porting
    1. Porting a Google Chrome extension
    2. Porting a legacy Firefox add-on
    3. Embedded WebExtensions
    4. Comparison with the Add-on SDK
    5. Comparison with XUL/XPCOM extensions
    6. Chrome incompatibilities
  6. Firefox workflow
    1. Temporary Installation in Firefox
    2. Debugging
    3. Getting started with web-ext
    4. web-ext command reference
    5. WebExtensions and the Add-on ID
    6. Publishing your WebExtension
  7. JavaScript APIs
    1. Browser support for JavaScript APIs
    2. alarms
    3. bookmarks
    4. browserAction
    5. browsingData
    6. commands
    7. contextMenus
    8. contextualIdentities
    9. cookies
    10. downloads
    11. events
    12. extension
    13. extensionTypes
    14. history
    15. i18n
    16. identity
    17. idle
    18. management
    19. notifications
    20. omnibox
    21. pageAction
    22. runtime
    23. sessions
    24. sidebarAction
    25. storage
    26. tabs
    27. topSites
    28. webNavigation
    29. webRequest
    30. windows
  8. Manifest keys
    1. applications
    2. author
    3. background
    4. browser_action
    5. chrome_url_overrides
    6. commands
    7. content_scripts
    8. content_security_policy
    9. default_locale
    10. description
    11. developer
    12. homepage_url
    13. icons
    14. manifest_version
    15. name
    16. omnibox
    17. options_ui
    18. page_action
    19. permissions
    20. short_name
    21. sidebar_action
    22. version
    23. web_accessible_resources
  9. Add-on SDK
  10. Getting started
    1. Installation
    2. Getting started
    3. Troubleshooting
  11. High-Level APIs
    1. addon-page
    2. base64
    3. clipboard
    4. context-menu
    5. hotkeys
    6. indexed-db
    7. l10n
    8. notifications
    9. page-mod
    10. page-worker
    11. panel
    12. passwords
    13. private-browsing
    14. querystring
    15. request
    16. selection
    17. self
    18. simple-prefs
    19. simple-storage
    20. system
    21. tabs
    22. timers
    23. ui
    24. url
    25. webextension
    26. widget
    27. windows
  12. Low-Level APIs
    1. /loader
    2. chrome
    3. console/plain-text
    4. console/traceback
    5. content/content
    6. content/loader
    7. content/mod
    8. content/symbiont
    9. content/worker
    10. core/heritage
    11. core/namespace
    12. core/promise
    13. dev/panel
    14. event/core
    15. event/target
    16. frame/hidden-frame
    17. frame/utils
    18. fs/path
    19. io/byte-streams
    20. io/file
    21. io/text-streams
    22. lang/functional
    23. lang/type
    24. loader/cuddlefish
    25. loader/sandbox
    26. net/url
    27. net/xhr
    28. places/bookmarks
    29. places/favicon
    30. places/history
    31. platform/xpcom
    32. preferences/event-target
    33. preferences/service
    34. remote/child
    35. remote/parent
    36. stylesheet/style
    37. stylesheet/utils
    38. system/child_process
    39. system/environment
    40. system/events
    41. system/runtime
    42. system/unload
    43. system/xul-app
    44. tabs/utils
    45. test/assert
    46. test/harness
    47. test/httpd
    48. test/runner
    49. test/utils
    50. ui/button/action
    51. ui/button/toggle
    52. ui/frame
    53. ui/id
    54. ui/sidebar
    55. ui/toolbar
    56. util/array
    57. util/collection
    58. util/deprecate
    59. util/list
    60. util/match-pattern
    61. util/object
    62. util/uuid
    63. window/utils
  13. Firefox for Android
  14. Getting started
    1. Walkthrough
    2. Debugging
    3. Code snippets
  15. APIs
    1. Accounts.jsm
    2. BrowserApp
    3. HelperApps.jsm
    4. Home.jsm
    5. HomeProvider.jsm
    6. JavaAddonManager.jsm
    7. NativeWindow
    8. Notifications.jsm
    9. PageActions.jsm
    10. Prompt.jsm
    11. RuntimePermissions.jsm
    12. Snackbars.jsm
    13. Sound.jsm
    14. Tab
  16. Legacy
  17. Restartless extensions
    1. Overview
  18. Overlay extensions
    1. Overview
  19. Themes
  20. Lightweight themes
    1. Overview
  21. Complete themes
    1. Overview
  22. Publishing add-ons
  23. Guides
    1. Signing and distribution overview
    2. Submit an add-on
    3. Review policies
    4. Developer agreement
    5. Featured add-ons
    6. Contact addons.mozilla.org
  24. Community and support
  25. Channels
    1. Add-ons blog
    2. Add-on forums
    3. Stack Overflow
    4. Development newsgroup
    5. IRC Channel