Repository navigation
Build: add exports map and Node-valid ESM to the devextreme package - #36224
Open
ajivanyandev wants to merge 4 commits into
Open
ajivanyandev wants to merge 4 commits into
ajivanyandev wants to merge 4 commits into
Conversation
- esm/: relative imports are fully specified by a new Babel plugin (build/babel-plugin-add-import-extensions.js), so Node's ESM loader and strict-ESM bundler modes can load the package. It resolves against the sources, so dotted file names such as ui.errors work, and it fails the build on an import it cannot resolve. - esm/: import @babel/runtime/helpers/* instead of helpers/esm/* (drop useESModules). The helper resolves to ESM or CJS through @babel/runtime's exports map, so Jest can load it when it transforms esm/. - package.json: new generate-exports-map executor and build:npm:exports-map target. One entry per module stub with types, module, import, require and default conditions; `module` first keeps import and require() on one copy in bundlers. Type-only modules come from the declarations. Assets, bundles/*, esm/* and cjs/* deep paths and *.d type imports are kept. - create-dual-mode-manifest: follow fully specified imports when collecting sideEffects. - state-manager-optimize: fully specified ESM re-export. - js/localization/ldml/number.js: drop a type-only re-export that fails in Node ESM. - js/viz/core/renderers/animation.js: relative import instead of a bare '__internal/...' path that never resolved outside the build. cjs/, the per-folder stubs and the rest of the npm package are unchanged.
The QUnit runner's import map gives tests extensionless URLs. Library code importing `./errors.js` and a test importing `ui/widget/ui.errors` loaded two instances of the same module, so stubs and spies set by tests did not reach the library. The `qunit` configurations of the ESM transpile targets now use a separate `esmQunit` Babel config: the npm `esm` config without the import-extensions plugin. The npm package output is unchanged.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The export mappings break existing suffixed bundle and declaration imports by duplicating extensions, and directory deep imports by forcing nonexistent .js paths instead of resolving index.js files.
2 open issues
What changed in this PR
This PR adds a generated exports map and Node-compatible ESM import paths to the published DevExtreme package, while retaining CommonJS output and QUnit’s extensionless imports.
Changes:
- Generates conditional exports for runtime modules, declarations, and asset paths.
- Adds source-aware ESM import rewriting with a separate QUnit configuration.
- Updates supporting build logic and tests, and fixes two public entry points.
| File | Description |
|---|---|
packages/nx-infra-plugin/src/executors/state-manager-optimize/state-manager-optimize.impl.ts |
Adds .js to the generated production re-export. |
packages/nx-infra-plugin/src/executors/state-manager-optimize/executor.e2e.spec.ts |
Updates ESM and CommonJS output expectations. |
packages/nx-infra-plugin/src/executors/generate-exports-map/schema.ts |
Defines exports-map executor options. |
packages/nx-infra-plugin/src/executors/generate-exports-map/schema.json |
Describes executor configuration fields. |
packages/nx-infra-plugin/src/executors/generate-exports-map/generate-exports-map.impl.ts |
Generates conditional exports and validates explicit targets. |
packages/nx-infra-plugin/src/executors/generate-exports-map/executor.ts |
Exposes the new executor. |
packages/nx-infra-plugin/src/executors/generate-exports-map/executor.e2e.spec.ts |
Tests runtime exports, declaration exports, and missing targets. |
packages/nx-infra-plugin/src/executors/create-dual-mode-manifest/side-effect-finder.ts |
Supports fully specified imports during side-effect discovery. |
packages/nx-infra-plugin/src/executors/create-dual-mode-manifest/executor.e2e.spec.ts |
Tests side-effect discovery across both import styles. |
packages/nx-infra-plugin/executors.json |
Registers the exports-map executor. |
packages/devextreme/project.json |
Wires exports generation into npm builds and selects QUnit transpilation settings. |
packages/devextreme/js/viz/core/renderers/animation.js |
Corrects the internal animation import to a relative path. |
packages/devextreme/js/localization/ldml/number.js |
Removes a runtime re-export of a TypeScript interface. |
packages/devextreme/build/transpile-config.js |
Separates npm and QUnit ESM settings and updates Babel helper imports. |
packages/devextreme/build/babel-plugin-add-import-extensions.test.ts |
Tests source resolution and import-path rewriting. |
packages/devextreme/build/babel-plugin-add-import-extensions.js |
Adds fully specified paths to relative ESM imports and re-exports. |
Review effort: Balanced
| "packageDir": "./artifacts/npm/devextreme", | ||
| "ignore": ["__internal", "bin", "bundles", "cjs", "dist", "esm", "license", "scss"], | ||
| "extraExports": { | ||
| "./bundles/*": { "types": "./bundles/*.d.ts", "default": "./bundles/*.js" }, |
| "./esm/*": "./esm/*.js", | ||
| "./cjs/*.json": "./cjs/*.json", | ||
| "./cjs/*.js": "./cjs/*.js", | ||
| "./cjs/*": "./cjs/*.js", |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Generates an
exportsmap for thedevextremenpm package and makesesm/valid Node ESM, whilecjs/keeps shipping. Supersedes the research in #34182: its extension rule skipped file names that contain a dot (495 imports), and its exports map left out type-only modules, the package root andbundles/*.What does the PR change?
Package output
esm/loads in Node. Every relative import is fully specified (./button→./button.js,./grids→./grids/index.js). Todayimport('devextreme/ui/button')fails in Node withERR_UNSUPPORTED_DIR_IMPORT, so SSR and plain Node code only work throughcjs/.esm/imports@babel/runtime/helpers/*instead ofhelpers/esm/*. These paths resolve to the ESM or CJS helper through@babel/runtime's own exports map, so tools that runesm/as CommonJS (Jest withtransformIgnorePatterns) can load them.package.jsongets anexportsmap (618 entries):types,module,import,requireanddefaultconditions;ui/button_types,data,core, …);"."(types only, from the existingtypesfield),./package.json,./bundles/*,./localization/messages/*.json,./dist/*,./scss/*;./esm/*and./cjs/*, so existing deep imports keep working;./*.d, forimport type … from 'devextreme/ui/menu.d'(used in our TestCafe tests).Nothing else in the package changes.
cjs/, the per-folderpackage.jsonstubs (includingsideEffects) and all other files are byte-identical to a build ofmain.Two public modules fixed
js/localization/ldml/number.jsre-exportedFormatterConfig, a TypeScript interface. Bundlers only warn about it; Node ESM fails with "does not provide an export named". Nothing imports it from this path.js/viz/core/renderers/animation.jsimported the bare path'__internal/viz/core/renderers/animation', which doesn't resolve outside our build. It fails underrequire()today as well.How did you achieve this?
build/babel-plugin-add-import-extensions.js, added to theesmconfig inbuild/transpile-config.js. It resolves each relative import against the source tree, the way TypeScript does, so dotted names such asui.errorsoremitter.feedbackget.js. A file wins over a directory with the same name.__internalfiles compiled intoartifacts/dist_tsare mapped back tojs/. An import that doesn't resolve fails the build.generate-exports-mapexecutor innx-infra-plugin, and abuild:npm:exports-maptarget that runs afterbuild:npm:root-package-jsonin everybuild:npmconfiguration, internal ones included. It fails if an entry points to a missing file.create-dual-mode-manifest: the side-effect finder appended.jsto every import, so fully specified imports would have produced emptysideEffectslists.state-manager-optimize: the ESM re-export it writes is now./prod/index.js.build:dev,build:qunit-esm,pnpm run dev) use a separateesmQunitBabel config:esmwithout the extensions plugin. The QUnit runner's import map gives tests extensionless URLs, and a test and the library must import a module by the same URL to share one instance. With.jsimports in the library, stubs and spies set by tests didn't reach it, and 13 QUnit jobs failed on the first CI run. The import paths are the only difference, so QUnit still covers the same code.Decisions worth reviewing
modulecomes first in each entry. With onlyimport/require(as in Build: research for generating exports for ESM mode #34182), an app that both imports andrequire()s DevExtreme loads two copies in webpack and esbuild. Config, localization and the license key then land in a copy the components don't use. Withmodulefirst, webpack resolves exactly as it does today through the stub'smodulefield, and esbuild matches it. Node and Jest ignoremodule, sorequire()still getscjs/and the class itself.require('devextreme/ui/button')now gets{ default }. That's what webpack users already get today.devextreme-aspnet-data-nojqueryalready unwraps.defaultfor this reason."type": "module"inesm/. Node 24 loads it through syntax detection without a warning insidenode_modules. Adding the field made webpack treat our files as strict ESM. That changed the bundled output for modules that default-import CommonJS/UMD libraries (Quill, Gantt, Diagram) and adds runtime risk with no benefit for Node.How can we verify these changes?
Results from a local run, compared with a build of
main(Node 24.16.0):mainpackage.jsondiffers only byexports.cjs/, stubs and other files identical.esm/differs only in import paths (2,011 files) plus the two module fixes.import()of all 505 public modules in Nodeaspnet(they fail underrequire()too), andjquery/knockout/olintegrations without those packages installed.require()of all 505 public modulesviz/core/renderers/animationnow loads.e2e/bundlers(webpack ESM + CJS, Rollup, Vite, Parcel, Browserify)e2e/compilation-cases(moduleResolution: bundler)devextreme-angular,devextreme-react,devextreme-vuebuilds; React and Vue testsbuild-vendor-bundles(esbuild)mainnx-infra-plugintests;devextremenode-testsmaintoo.transformIgnorePatterns,jest.mock), Vitest, Noderequire/import, webpack, esbuild, Browserify, TypeScriptbundler/node10mainexcept: Nodeimportand webpack imports from.mjs/"type":"module"app files now pass; esbuildrequire()-only code gets{ default }. Apps mixingimportandrequire()still get one copy in webpack and esbuild.Not run locally: TestCafe, Playwright.
Known limitations
import { RRule, RRuleSet } from 'rrule'; rrule'smainis a CommonJS bundle whose named exports Node can't detect, and its ESM build isn't valid Node ESM. It doesn't load today either, Vitest handles it, andrequire()still works. A fix in our import would add a webpack warning for every Scheduler app, so it's left for a follow-up.apps/demos/utils/server/csp-bundle.jshas an esbuild plugin that collapsescjs/paths toesm/. With themodulecondition esbuild should no longer resolvecjs/there; I left the plugin in place..d.tsfiles are CommonJS-format for TypeScript (node16/nodenextwith an ESM importer). This is unchanged from today.