genkgo / babel-plugin-dynamic-import-amd

Babel plugin to transpile import() to require, for AMD module loaders
MIT License
2 stars 2 forks source link

Problem with requirejs #1

Open webcodepl opened 6 years ago

webcodepl commented 6 years ago

In my case plugin produces this code:

new Promise(resolve => resolve(require(['TestController']))).then(TestController => { let controller = new TestController(); })

Browser reports: "Unhandled promise rejection TypeError: TestController is not a constructor"

When i changed this code manualy to:

new Promise(resolve => require(['TestController'], (TestController) => resolve(TestController))).then(TestController => { let controller = new TestController(); })

Works ok.

frederikbosch commented 6 years ago

Which AMD module loader do you use? I am using the ember-cli/loader.js library. Maybe that's why there are errors?

webcodepl commented 6 years ago

I am using requirejs. Maybe that is a problem but It would be nice if it worked with requirejs too :)

Thanks.

frederikbosch commented 6 years ago

@tomaszpupiec I am interested though in why that would not work with requirejs since they should be compatible with each other.

DornieDortsch commented 6 years ago

@tomaszpupiec I am running in the same problem using a "real async" AMD loader like requirejs.

There is is a fork by @rtasarz with an "alternate syntax for require" 5ea10423cca4309f119a6854fe1811adfbf3297f that works for me. https://github.com/rtasarz/babel-plugin-dynamic-import-amd

@frederikbosch AMD defines async callback-style and synchron string-style of require. I have to use callback-style to load modules async in the browser.

webcodepl commented 6 years ago

I confirm, this fork works for me too. Thanks.