Why does LuciadRIA recommend moduleResolution: nodenext?
LuciadRIA modules comply with the ECMAScript Modules (ESM) resolution algorithm, which allows browsers to load LuciadRIA without
a bundler.
The "moduleResolution": "nodenext" TypeScript setting follows the same Node.js ESM resolution rules and is therefore aligned with how LuciadRIA packages are
structured.
The older "moduleResolution": "node" setting uses TypeScript’s classic CommonJS algorithm, which predates ESM and does not understand package.json exports fields or explicit .js extensions.
Using it with LuciadRIA will cause import resolution errors.
See ES Modules as of LuciadRIA 2023.0 for more background.
Can I keep using moduleResolution: bundler?
Yes. You can use "moduleResolution": "bundler" with LuciadRIA. LuciadRIA itself already uses explicit .js extensions in all its internal imports, so there is no fundamental incompatibility.
The important constraint is that imports from LuciadRIA packages must include the .js extension. This applies regardless of whether you use nodenext or bundler.
The reason is that LuciadRIA’s package.json contains the following exports map:
"exports": {
"./*": "./*"
}
Unlike the old CommonJS require(), Node.js ESM resolution with an explicit exports map does not automatically append extensions. It resolves paths exactly
as written.
This means a bundler cannot find a file like @luciad/ria/view/RIAMap if the actual file on disk is RIAMap.js.
In practice, you need to write:
import {RIAMap} from "@luciad/ria/view/RIAMap.js";
rather than:
import {RIAMap} from "@luciad/ria/view/RIAMap";
The key difference between nodenext and bundler is that nodenext enforces extension-explicit imports in your own code as well, while bundler does not. If your other libraries require bundler, switching to bundler and keeping .js extensions on LuciadRIA imports is a supported approach.
How can I use extension-less imports with bundler module resolution?
The recommended approach is to use explicit .js extensions on all LuciadRIA imports.
LuciadRIA intentionally ships with a single-form exports map to avoid two known problems with supporting both forms simultaneously:
-
Inconsistent imports across the codebase: with both forms accepted, some imports will use the
.jsextension and others will not, making the codebase inconsistent. -
Duplicate IDE suggestions: IDEs will offer two auto-complete suggestions for every LuciadRIA import, one with and one without the
.jsextension.
If you still need extension-less imports, you can patch the exports field in LuciadRIA’s package.json to accept both forms:
"exports": {
"./*.js": {
"types": "./*.d.ts",
"import": "./*.js",
"default": "./*.js"
},
"./*": {
"types": "./*.d.ts",
"import": "./*.js",
"default": "./*"
}
}
Apply this change to the package.json of each LuciadRIA package you use (for example, <luciadria_installation>/packages/ria/package.json and any optional packages or toolbox components).
|
You must reapply this patch every time you update to a new LuciadRIA version, because the package files are replaced during an update. |