SSR errors with GoJS 2.2.7 and Nuxt3

Hello!

I have found an issue with using gojs and nuxt3.
Nuxt now try to load modules on node instead of commonjs.

To be able to interpret a file as a module, nodes requires that the files end with .mjs extension or the have type: “module” in its package.json.

The recommended way is to use extension.

I have made a fix on a fork, but can we see this in the official release?

fix: add mjs extension to release module · digisquad-io/GoJS@2b60017 (github.com)

We cannot make that change because some tools do not recognize the MJS extension.

Anyway, there already is a “go.mjs” file in that directory:

Are you saying that Nuxt doesn’t use “go.mjs” automatically?

Yes, in Nuxt3 everything is module, from server with node to frontend with <script type="module">.
If we try to load a commonjs script it will be transpiled to esm first, this is made by vitejs: Dependency Pre-Bundling | Vite (vitejs.dev)

By default, node treat .js and .cjs files as commonjs and .mjs as modules.
If we set "type": "module" in our package.json, it will treat .js as modules instead of commonjs for all files, breaking third party packages.

Setting “module” entrypoint to your package.json only point which file should be used when using import statement, but not force to be interpreted as module.

I’ve ended using this as import, but it looses all typescript declaration:

<script setup lang="ts">
import * as go from 'gojs/release/go.mjs'
</script>

Yes, that is one of the tools that does not support MJS as a file extension.

I also don’t understand why when the package.json says that some file is an ES module, why doesn’t Nuxt accept that?

  "module": "release/go-module.js"