Geequlim / ECMAScript

Javascript binding for godotengine
MIT License
959 stars 84 forks source link

CommonJS Module Support #155

Open animanmaster opened 1 year ago

animanmaster commented 1 year ago

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?

GTNT-Github commented 1 year ago

I'm having the same issue, any info?

sr229 commented 11 months ago

Most likely missing the CommonJS module resolution in the engine.

nmerget commented 11 months ago

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?

Geequlim commented 11 months ago

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