Skip to content

Give the pasted-text import an extension so the node test runner can load it - #8981

Merged
danielhanchen merged 1 commit into
mainfrom
fix-esm-ext
Aug 16, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-esm-ext

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Frontend build + bundle sanity is red on main. tests/delete-chat-files-preference.test.ts fails with:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module
  .../studio/frontend/src/features/chat/utils/pasted-text

and the file is right there. The missing piece is the extension.

Cause

The frontend suite runs under node --experimental-strip-types --test, and Node's ESM resolver does not append extensions. #8963 added

} from "../utils/pasted-text";

to chat-preferences-store.ts, and the test imports that store for its value:

import { useChatPreferencesStore } from "../src/features/chat/stores/chat-preferences-store.ts";

so the resolver is asked for a file literally named pasted-text, and there is not one.

The two sibling modules importing the same file already write it with the extension, use-chat-search-index.ts and prompt-storage-dialog.tsx, so this restores the existing convention rather than inventing one.

Reproduced in isolation

$ node --experimental-strip-types a_noext.ts   # import { x } from "./b"
Error [ERR_MODULE_NOT_FOUND]: Cannot find module .../b

$ node --experimental-strip-types a_ext.ts     # import { x } from "./b.ts"
resolved 1

Scope, and why this is one line

47 other relative imports without an extension live in modules the tests name, which looks alarming until you separate them. All but two are erased before resolution: they are import type, or a braced clause containing nothing but type members, so type stripping removes them and the resolver never sees the specifier.

The two genuine value imports are chat-settings-api.ts -> ../utils/settings-retry and per-model-config.ts -> ./model-identity. Neither is reached at runtime: the tests that mention those files hand the path to readFile and assert on the source text, or import only their types. They are latent rather than broken, so they are not touched here. They will bite the day a test imports either module for its value, which is worth a follow-up but not a silent change in a red-main fix.

…load it

Frontend build + bundle sanity is red on main. tests/delete-chat-files-preference.test.ts
fails with ERR_MODULE_NOT_FOUND for
studio/frontend/src/features/chat/utils/pasted-text, and the file is there.

The frontend suite runs under `node --experimental-strip-types --test`, and
Node's ESM resolver does not add extensions. #8963 added

    } from "../utils/pasted-text";

to chat-preferences-store.ts, which the test imports for its value, so the
resolver is asked for a file called pasted-text and there is not one. The two
sibling modules that import the same file, use-chat-search-index.ts and
prompt-storage-dialog.tsx, both write ../utils/pasted-text.ts, which is the
convention this restores.

Reproduced the mechanism on its own: a.ts importing "./b" fails with
ERR_MODULE_NOT_FOUND under --experimental-strip-types, and "./b.ts" resolves.

Scope. 47 other relative imports without an extension sit in modules the tests
name, but all except two are erased before resolution, being `import type` or a
braced clause of nothing but types. The two real ones,
chat-settings-api.ts -> ../utils/settings-retry and
per-model-config.ts -> ./model-identity, are not reached at runtime: the tests
that mention those files pass them to readFile as source text, or import only
their types. They are latent rather than broken, so they are left alone here
and worth a separate look.
@danielhanchen

Copy link
Copy Markdown
Member Author

Verified this properly rather than on the CI log plus a synthetic repro, and correcting one claim in the description while I am here.

Ran the real test both ways, with the frontend dependencies installed:

without the fix:  ERR_MODULE_NOT_FOUND ... /features/chat/utils/pasted-text
                  imported from .../stores/chat-preferences-store.ts
                  pass 0

with the fix:     pass 6, fail 0

Full suite on this branch: 2843 passed, 0 failed.

Correction to the description. I wrote that use-chat-search-index.ts and prompt-storage-dialog.tsx write ../utils/pasted-text.ts and that this restores "the convention". They do write it that way, but I implied they do so because they are reachable from the node runner, and that is not established: neither is directly imported by a test at runtime. Of the seven modules importing pasted-text, only chat-preferences-store.ts is, which is exactly why it is the only one that breaks.

So the argument for this fix is not convention, it is the resolver: node --experimental-strip-types does not append extensions, so any module a test imports for its value must spell out .ts. That happens to be a stronger reason than the one I gave.

I also considered the other direction, that the runner is at fault rather than the import, since extensionless is the majority style in this file's neighbourhood (five of the seven importers). Making Node resolve extensionless relative TS specifiers needs a custom loader; type stripping deliberately does not do TS-style resolution. That is a real option but it is a tooling change, not a red-main fix, and it would be worth doing only alongside a guard.

Which brings up the gap worth a follow-up: there is no lint or test enforcing that a runtime-reachable relative import carries an extension, which is why this reached main. The two latent cases named in the description would be caught by such a check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant