overte-org / overte

Overte open source virtual worlds platform.
https://overte.org/
Other
132 stars 48 forks source link

Add ECMAScript module support #584

Open ksuprynowicz opened 11 months ago

ksuprynowicz commented 11 months ago

https://v8docs.nodesource.com/node-18.16/df/d74/classv8_1_1_module.html https://nodejs.org/api/esm.html#modules-ecmascript-modules https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

Zetaphor commented 11 months ago

If we integrate bounties as discussed in-world, I'd gladly fund this effort

keeshii commented 11 months ago

Not sure if we should mix CommonJs and EsModules. In node.js there is a switch in package.json type: "module". If it is turned on, then the whole app must use import statements, any occurance of the require causes errors:

node index.js 
file:///home/keeshii/repos/test-app/index.js:4
var fs = require('fs');
         ^

ReferenceError: require is not defined in ES module scope, you can use import instead

On the other hand, if we remove the type: module from package.json, the import statements are not supported:

(node:5728) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/keeshii/repos/test-app/index.js:1
import { App } from './source/app.js';
daleglass commented 10 months ago

585 added the require() bit

daleglass commented 10 months ago

587 probably still needs a fix