fix(observable): add explicit extensions to relative ESM imports - #5307
Merged
Conversation
Relative import/export specifiers in @equinor/fusion-observable's source lacked file extensions (e.g. './operators' instead of './operators/index.js'). Under the package's inherited moduleResolution: bundler tsconfig, tsc never adds them, so the compiled ESM output only resolves for bundler-based consumers. Consumers resolving the published dist directly under strict Node.js ESM (e.g. vitest without a bundler) fail with module-not-found errors. Add explicit .js/.js/index.js extensions to every relative import/export in src, and override the package's own tsconfig to module/moduleResolution: nodenext so tsc enforces this going forward instead of silently regressing.
🦋 Changeset detectedLatest commit: bd1fbb7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 15 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes strict Node.js ESM resolution for @equinor/fusion-observable.
Changes:
- Adds explicit
.jsor/index.jsextensions to relative module specifiers. - Enables NodeNext resolution to enforce valid ESM imports.
- Adds a patch changeset.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
.changeset/observable_fix-esm-import-extensions.md |
Documents the ESM resolution fix. |
packages/utils/observable/tsconfig.json |
Enables NodeNext module resolution. |
packages/utils/observable/src/types/reducers.ts |
Adds an explicit import extension. |
packages/utils/observable/src/types/index.ts |
Adds explicit export extensions. |
packages/utils/observable/src/to-observable.ts |
Adds an explicit import extension. |
packages/utils/observable/src/react/useObservableState.ts |
Uses the explicit types entry point. |
packages/utils/observable/src/react/useObservableSelectorState.ts |
Adds explicit relative extensions. |
packages/utils/observable/src/react/useObservableSelector.ts |
Adds explicit relative extensions. |
packages/utils/observable/src/react/useObservableRef.ts |
Adds explicit relative extensions. |
packages/utils/observable/src/react/useObservableInputState.ts |
Adds explicit hook import extensions. |
packages/utils/observable/src/react/useObservableFlow.ts |
Adds explicit type import extensions. |
packages/utils/observable/src/react/useObservableEffect.ts |
Adds explicit type import extensions. |
packages/utils/observable/src/react/useObservable.ts |
Adds explicit relative extensions. |
packages/utils/observable/src/react/useDebounce.ts |
Uses the explicit types entry point. |
packages/utils/observable/src/react/use-observable-epic.ts |
Adds an explicit hook import extension. |
packages/utils/observable/src/react/index.ts |
Adds explicit React barrel extensions. |
packages/utils/observable/src/operators/switch-map-action.ts |
Adds explicit operator import extensions. |
packages/utils/observable/src/operators/map-prop.ts |
Uses the explicit types entry point. |
packages/utils/observable/src/operators/map-action.ts |
Adds explicit operator import extensions. |
packages/utils/observable/src/operators/index.ts |
Adds explicit operator barrel extensions. |
packages/utils/observable/src/operators/filter-action.ts |
Uses the explicit types entry point. |
packages/utils/observable/src/index.ts |
Adds explicit root barrel extensions. |
packages/utils/observable/src/FlowSubject.ts |
Adds explicit internal module extensions. |
packages/utils/observable/src/create-state.ts |
Adds explicit internal module extensions. |
packages/utils/observable/src/create-reducer.ts |
Adds explicit type import extensions. |
packages/utils/observable/src/actions/utils.ts |
Adds an explicit action import extension. |
packages/utils/observable/src/actions/predicates.ts |
Adds explicit action import extensions. |
packages/utils/observable/src/actions/index.ts |
Adds explicit action barrel extensions. |
packages/utils/observable/src/actions/create-async-action.ts |
Adds explicit action import extensions. |
packages/utils/observable/src/actions/create-action.ts |
Adds explicit import and export extensions. |
packages/utils/observable/src/actions/ActionError.ts |
Adds an explicit type import extension. |
packages/utils/observable/src/actions/action-mapper.ts |
Adds an explicit type import extension. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
odinr
marked this pull request as ready for review
August 16, 2026 20:15
odinr
added a commit
that referenced
this pull request
Aug 19, 2026
Relative import/export specifiers in @equinor/fusion-observable's source lacked file extensions (e.g. './operators' instead of './operators/index.js'). Under the package's inherited moduleResolution: bundler tsconfig, tsc never adds them, so the compiled ESM output only resolves for bundler-based consumers. Consumers resolving the published dist directly under strict Node.js ESM (e.g. vitest without a bundler) fail with module-not-found errors. Add explicit .js/.js/index.js extensions to every relative import/export in src, and override the package's own tsconfig to module/moduleResolution: nodenext so tsc enforces this going forward instead of silently regressing.
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.
Why is this change needed?
@equinor/fusion-observable's relative import/export specifiers (e.g../operators,../types) had no file extensions. The package's tsconfig inheritsmoduleResolution: "bundler"from the repo root, sotscnever rewrote these to.js//index.jsin the compiled ESM output. That's fine for bundler-based consumers (Vite/webpack), but breaks strict Node.js ESM resolution for any consumer that resolves the publisheddist/esmoutput directly (e.g. Vitest running without a bundler), producing module-not-found errors. A downstream consumer had already worked around this with ayarn patch.What is the current behavior?
Compiled
dist/esm/*.jsfiles import sibling modules without extensions (from './operators'), which fails to resolve under strict Node ESM.What is the new behavior?
Every relative import/export in
src/**/*.tsnow has an explicit.js(file) or/index.js(directory) extension, so the compiled output resolves correctly under both bundler and strict Node ESM resolution. The package's owntsconfig.jsonnow overridesmodule/moduleResolutiontonodenextsotscenforces explicit extensions going forward instead of silently allowing them to be omitted again.What is the intended behavior or invariant?
@equinor/fusion-observable's published ESM output must be resolvable by both bundler-based and non-bundler (native Node ESM) consumers. The package-localnodenextoverride only affects how this package type-checks its own imports; it does not change how other packages (still onmoduleResolution: "bundler") consume this package's emitted.d.ts/.jsoutput.Does this PR introduce a breaking change?
No. Output paths and public API are unchanged; only the internal module specifiers gained explicit extensions.
Impact assessment:
packages/react/app,packages/modules/*,packages/dev-portal) still build cleanly viatsc -bsince they still usemoduleResolution: "bundler"and consume the emitted declaration/JS files, not the source.Review guidance:
Diff is mechanical (adding extensions) across ~30 files in
packages/utils/observable/src; the interesting parts are tsconfig.json (thenodenextoverride) and FlowSubject.ts as a representative example. Verified:tsc -b --force,vitest run(42/42 tests),biome check, andfusion-lintall pass; a downstream project-reference build (packages/react/app) also builds clean.Additional context
The two dead test files under
src/__tests__/(Query.test.ts,ReactiveObservable.test.ts) reference modules that no longer exist and are excluded from both this package'stsconfig.jsonand itsvitest.config.ts(test.include: ['tests/**']); they were intentionally left untouched as out of scope.Related issues
None.
Checklist