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?
@suhomlineugene This sort of question may be better asked/answered on StackOverflow where it will be easier to search for and find answers later.
@rossta I posted it to SO. Here is link https://stackoverflow.com/questions/49138589/import-js-file-to-webpack-application-js/49140415#49140415.
@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'
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 doimport HelloWorld from 'generated'