[js_repl] Support local ESM file imports#13437
Merged
aaronl-openai merged 9 commits intomainfrom Mar 5, 2026
Merged
Conversation
Allow js_repl to import relative and absolute local .js/.mjs files while keeping package loading on the native path and documenting the ESM-only/local-static-import contract. Co-authored-by: Codex <noreply@openai.com>
fjord-oai
reviewed
Mar 4, 2026
Contributor
There was a problem hiding this comment.
from my local codex conversation:
[P3] Top-level static local imports still fail with a low-level VM error. In kernel.js (line 1004) the cell linker returns importResolved(...); for file specifiers, that path (line 432) returns module.namespace, not a vm.Module. So import "./foo.js" still trips ERR_VM_MODULE_NOT_MODULE rather than a purposeful js_repl message.
fjord-oai
reviewed
Mar 4, 2026
Contributor
There was a problem hiding this comment.
codex also suggested:
I’d add one runtime test proving an imported local file can see REPL globals such as codex.tmpDir or captured console. That’s the behavior a future “simplify to native import” refactor is most likely to break.
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Make package results from import.meta.resolve() round-trip through the native package loader, and align the public and injected js_repl docs with the current local-file import behavior, VM-context semantics, and per-exec reload rules. Co-authored-by: Codex <noreply@openai.com>
Update the local-file ancestor node_modules test to use a dynamic bare import so it actually covers the runtime search-root restriction instead of the separate static-bare-import rejection path. Co-authored-by: Codex <noreply@openai.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
js_replsupport for dynamic imports of relative and absolute local ESM.js/.mjsfilesCODEX_JS_REPL_NODE_MODULE_DIRS, thencwd), even when they originate from imported local files.js/.mjsfiles, and surface a clear error for unsupported top-level static imports in the REPL cellcodex.tmpDir,codex.tool, capturedconsole, and Node-likeimport.metahelpersawait import("./file.js")calls pick up edits and fixed failures, while preserving package/builtin caching and persistent top-level REPL bindingsimport.meta.resolve()self-consistent by allowing the returnedfile://...URLs to round-trip throughawait import(...)js_repldocs to clarify the narrowed contract, including global bare-import resolution behavior for local absolute filesTesting
cargo test -p codex-core js_repl_