{"action":"created","issue":{"url":"https://api.github.com/repos/marionettejs/backbone.marionette/issues/2576","labels_url":"https://api.github.com/repos/marionettejs/backbone.marionette/issues/2576/labels{/name}","comments_url":"https://api.github.com/repos/marionettejs/backbone.marionette/issues/2576/comments","events_url":"https://api.github.com/repos/marionettejs/backbone.marionette/issues/2576/events","html_url":"https://github.com/marionettejs/backbone.marionette/issues/2576","id":82593024,"number":2576,"title":"Marionette w/ browserify + babelify requires downgrading and inline shim","user":{"login":"ashtonwar","id":6740947,"avatar_url":"https://avatars.githubusercontent.com/u/6740947?v=3","gravatar_id":"","url":"https://api.github.com/users/ashtonwar","html_url":"https://github.com/ashtonwar","followers_url":"https://api.github.com/users/ashtonwar/followers","following_url":"https://api.github.com/users/ashtonwar/following{/other_user}","gists_url":"https://api.github.com/users/ashtonwar/gists{/gist_id}","starred_url":"https://api.github.com/users/ashtonwar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashtonwar/subscriptions","organizations_url":"https://api.github.com/users/ashtonwar/orgs","repos_url":"https://api.github.com/users/ashtonwar/repos","events_url":"https://api.github.com/users/ashtonwar/events{/privacy}","received_events_url":"https://api.github.com/users/ashtonwar/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-29T21:23:59Z","updated_at":"2015-06-20T11:01:04Z","closed_at":"2015-06-20T11:01:04Z","body":"Whilst trying to include Marionette w/ browserify + babelify I encountered [this issue](https://github.com/jashkenas/backbone/issues/3291).\r\n\r\nThis es6 shim should have fixed the issue:\r\n\r\n```\r\nimport Backbone from 'backbone';\r\nimport $ from 'jquery';\r\nBackbone.$ = $;\r\nimport Marionette from 'backbone.marionette';\r\n```\r\n\r\nIn the latest version (6.1.2) of babelify this transpiles to:\r\n\r\n```\r\nvar _jquery = require('jquery');\r\nvar _jquery2 = _interopRequireDefault(_jquery);\r\nvar _backbone = require('backbone');\r\nvar _backbone2 = _interopRequireDefault(_backbone);\r\nvar _backboneMarionette = require('backbone.marionette');\r\nvar _backboneMarionette2 = _interopRequireDefault(_backboneMarionette);\r\n_backbone2['default'].$ = _jquery2['default'];\r\n```\r\n\r\njQuery obviously needs to be added before Marionette is required. Downgrading Babelify to 5.0.5 resolved this. I also downgraded Backbone to 1.1.2.\r\n\r\nMy files originally looked like this:\r\n\r\n```\r\n// main.js\r\nimport './plugins.js'\r\n\r\n...\r\n```\r\n\r\n```\r\n// plugins.js\r\nimport Backbone from 'backbone';\r\nimport $ from 'jquery';\r\nBackbone.$ = $;\r\nimport Marionette from 'backbone.marionette';\r\n```\r\n\r\nBut Backbone.$ was still undefined. Inlining plugins.js into main.js fixed this.\r\n\r\nRelevant files:\r\n\r\n```\r\n// gulpfile.js\r\n\r\n...\r\n\r\nconst bundler = _.memoize(function (watch) {\r\n  var options = { debug: true };\r\n  if (watch) { _.extend(options, watchify.args); }\r\n  var b = browserify('./public.src/CORE/main.js', options);\r\n  if (watch) { b = watchify(b); }\r\n  return b;\r\n});\r\n\r\nfunction bundle(cb, watch) {\r\n  return bundler(watch).bundle()\r\n    .on('error', handleErrors)\r\n    .pipe(source('script.js'))\r\n    .pipe(buffer())\r\n    .pipe(gulp.dest('./public.dist'))\r\n    .on('end', cb)\r\n    .pipe(reload({stream: true}));\r\n}\r\n\r\ngulp.task('scripts', function (cb) {\r\n  process.env.BROWSERIFYSWAP_ENV = 'dist';\r\n  bundle(cb, true);\r\n});\r\n\r\n...\r\n\r\n```\r\n\r\n```\r\n// package.json\r\n\r\n...\r\n\r\n  \"browserify-swap\": {\r\n    \"@packages\": [\r\n      \"underscore\"\r\n    ],\r\n    \"dist\": {\r\n      \"underscore.js$\": \"lodash\"\r\n    }\r\n  },\r\n  \"browserify\": {\r\n    \"transform\": [\r\n      \"babelify\",\r\n      [\r\n        \"hbsfy\",\r\n        {\r\n          \"extensions\": [\r\n            \"hbs\"\r\n          ]\r\n        }\r\n      ],\r\n      \"browserify-swap\"\r\n    ]\r\n  }\r\n\r\n...\r\n\r\n```\r\n\r\nIt'd be nice to at least see some documentation for this."},"comment":{"url":"https://api.github.com/repos/marionettejs/backbone.marionette/issues/comments/113746276","html_url":"https://github.com/marionettejs/backbone.marionette/issues/2576#issuecomment-113746276","issue_url":"https://api.github.com/repos/marionettejs/backbone.marionette/issues/2576","id":113746276,"user":{"login":"ahumphreys87","id":2510520,"avatar_url":"https://avatars.githubusercontent.com/u/2510520?v=3","gravatar_id":"","url":"https://api.github.com/users/ahumphreys87","html_url":"https://github.com/ahumphreys87","followers_url":"https://api.github.com/users/ahumphreys87/followers","following_url":"https://api.github.com/users/ahumphreys87/following{/other_user}","gists_url":"https://api.github.com/users/ahumphreys87/gists{/gist_id}","starred_url":"https://api.github.com/users/ahumphreys87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahumphreys87/subscriptions","organizations_url":"https://api.github.com/users/ahumphreys87/orgs","repos_url":"https://api.github.com/users/ahumphreys87/repos","events_url":"https://api.github.com/users/ahumphreys87/events{/privacy}","received_events_url":"https://api.github.com/users/ahumphreys87/received_events","type":"User","site_admin":false},"created_at":"2015-06-20T11:01:03Z","updated_at":"2015-06-20T11:01:03Z","body":"That's correct providing you use backbone 1.2 as that now loads jquery for you"}}