rmacklin/sprockets-bumble_d

Uncaught ReferenceError: require is not defined

Closed this issue · 3 comments

We have a rails (4.2.9) project and use the asset pipeline (sprockets 3.7.1) for our ember JS app (in CoffeeScript).

Ember has moved to es6 & modules and we would like to migrate over. I found this gem via Stack Overflow and it sounds like what we want.

Right now, if I simply take one of my files and change it from CoffeeScript to ES6 (and change the extension from .js.coffee to .es6) and go, I see that it gets transpiled to some standard format (CommonJS?) and the browser crashes with Uncaught ReferenceError: require is not defined where import DS from 'ember-data'; was transpiled to var _emberData = require('ember-data');.

From that point I have tried many, many things including carefully following the install steps on this gem two times. I haven't really gotten past the require error.

I think I am missing something really simple. Any help would be greatly appreciated. Thanks in advance.

Hi @gerry3,

From what you've shared, it seems like your ES6 modules are being transpiled to CommonJS modules rather than UMD modules. It's hard for me to spot the root cause without more information. Would you be able to either share more details/code of your setup or try to create a minimal application that reproduces the same issue (so that I could clone it and debug locally)?

@gerry3, I'd love to help you figure out the issue you're having, but as mentioned I don't currently have enough context to debug the issue. If you could provide more information about your setup (especially your babel and sprockets-bumble_d configurations) or ideally an application that reproduces the issue, that'd be really helpful.

The reproduction repository could be a stripped down version of your application with everything removed other than your babel and sprockets-bumble_d configurations, the file that does import DS from 'ember-data'; and one view that requests that JavaScript file, if that's enough to produce the error you're seeing. (If not, then it's likely the issue lies within some of the stripped out parts, so you can get incrementally less aggressive with what you strip out until the error is reproducible.) Alternatively, you could start with one of the test_apps from this gem's test suite and incrementally morph it toward the setup specific to your application until it can reproduce the issue.

@rmacklin thanks so much for the quick responses. I made some progress exploring how this stuff all works outside of this gem, but then got busy with other projects. I will close this for now, but re-open if I ultimately end up needing the gem & needing help with it.