ECMAScript icon indicating copy to clipboard operation
ECMAScript copied to clipboard

CommonJS Module Support

Open animanmaster opened this issue 1 year ago • 4 comments

The README seems to indicate that require-ing modules works, but when I tried to import a JS file that uses require(), I get a 'require' is not defined error message. Is the README incorrect, or is there a way to make JS files that use require work?

animanmaster avatar Apr 28 '23 05:04 animanmaster

I'm having the same issue, any info?

GTNT-Github avatar Aug 07 '23 19:08 GTNT-Github

Most likely missing the CommonJS module resolution in the engine.

sr229 avatar Oct 06 '23 07:10 sr229

The README seems to indicate that require-ing modules work, but when I tried to import a JS file that uses require(), I got a 'require' is not defined error message. Is the README incorrect, or is there a way to make JS files that use require work?

I think the documentation is incorrect. I couldn't find any hint in QuickJS about it. I also tested this workaround, but it leads to an error in QuickJS that the module is __null. There could be another issue when you want to use a nodeJS module like crypto: I think it is not implemented in QuickJS, so you need to get another package from npm that simulates the same logic.

Maybe https://github.com/IvanGaravito/quickjs-require could be something (it was the first repo I found)?

Besides this, a lot of CommonJS Modules can be used in ECMAScript or in Typescript with npm install --save-dev @types/xxx. Can you provide the module you used which didn't work as expected?

nmerget avatar Oct 09 '23 20:10 nmerget

CommonJS is removed. We recommend using a packager such as Webpack to solve the use of npm libraries

Geequlim avatar Oct 10 '23 05:10 Geequlim