NorthwoodsSoftware / GoJS

JavaScript diagramming library for interactive flowcharts, org charts, design tools, planning tools, visual languages.
http://gojs.net
Other
7.7k stars 2.86k forks source link

Compile warnings generated when using esbuild #204

Closed shollander closed 5 months ago

shollander commented 6 months ago

When using GoJS in an Angular 17 project that uses esbuild (now the default compiler for Angular), the following warnings are generated because of GoJS:

The CommonJS "module" variable is treated as a global variable in an ECMAScript module and may not work as expected [commonjs-variable-in-esm]

    node_modules/gojs/release/go-module.js:40592:74
        40592  | ... typeof module.exports && (module.exports = 'undefined' != ...
               |                                                 ~~~~~~~~~

This file is considered to be an ECMAScript module because of the "export" keyword here:

    node_modules/gojs/release/go-module.js:40679:0:
        40679  |  export const version = go.version;
               |  ~~~~~~

Note: We are currently using version 2.2.22 of GoJS, but this issue still appears in the latest version (2.3.14).

simonsarris commented 6 months ago

Possibly this is fixed in 2.3.16. Can you give it a try?

shollander commented 6 months ago

I still get esbuild warnings when using 2.3.16. The error is slightly different, but the idea is the same:

The CommonJS "module" variable is treated as a global variable in an ECMAScript module and may not work as expected [commonjs-variable-in-esm]

    node_modules/gojs/release/go-module.mjs:41685:74
        41685  |   'undefined' !== typeof module && 'object' === typeof module.exports && (module.exports = 'undefined' !== typeof global ? global.go : self.go);
               |                                                        ~~~~~~

I should mention that in order to see these warnings you need to run the build with the verbose flag (i.e. ng build --verbose).

simonsarris commented 5 months ago

We've changed this in the 3.0 (currently beta) branch, by removing any module.exports = ... from ESM files. We might change it for 2.3 also, but maybe not. It's difficult to make changes like this that may break some customer builds, however unlikely, so its a bit preferable to do it in a version bump.

3.0 will become the latest version soon.

simonsarris commented 5 months ago

If you want to try the 3.0 beta, 3.0.0-b7 has been released with this change.

npm i gojs@beta