Webpacker: Trying to import js file to webpack application js

Created on 6 Mar 2018  路  3Comments  路  Source: rails/webpacker

I have ruby project where I add typescript and webpacker

I have wrote typescript and make rake assets:tsc. So it compiles ts code to js.

Now I have welcome.js at folder `app/assets/javascripts/generated/welcome.js

Here is code of welcome.js

var HelloWorld = /** @class */ (function () { function HelloWorld(name) { this.name = name; } HelloWorld.prototype.print = function () { alert("Hello World, " + this.name + "!"); }; return HelloWorld; }()); new HelloWorld('John Doe').print(); //# sourceMappingURL=welcome.js.map

I tried to wrote in welcome.js

export default HelloWorld;

And in application.js wrote import HelloWorld from 'generated'

And gets this error

Uncaught Error: Cannot find module "generated" at Object. (application.js:1) at webpack_require (bootstrap 24a076357adc3b41e79b:19) at Object.defineProperty.value (bootstrap 24a076357adc3b41e79b:62) at bootstrap 24a076357adc3b41e79b:62

How I can solve it?

Most helpful comment

@suhomlineugene Should be import HelloWorld from 'generated/welcome' no? If you would have an index.js instead of welcome.js inside generated folder than you can simply do import HelloWorld from 'generated'

All 3 comments

@suhomlineugene This sort of question may be better asked/answered on StackOverflow where it will be easier to search for and find answers later.

@suhomlineugene Should be import HelloWorld from 'generated/welcome' no? If you would have an index.js instead of welcome.js inside generated folder than you can simply do import HelloWorld from 'generated'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FrankFang picture FrankFang  路  3Comments

naps62 picture naps62  路  3Comments

ijdickinson picture ijdickinson  路  3Comments

amandapouget picture amandapouget  路  3Comments

iChip picture iChip  路  3Comments