Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reproduction of loading commonjs modules from nextjs in the browser #903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
kasperpeulen wants to merge 4 commits into vitejs:main
base: main
Choose a base branch
Loading
from kasperpeulen:kasper/cjs-module-runner-in-browser

Conversation

@kasperpeulen
Copy link

@kasperpeulen kasperpeulen commented Oct 7, 2025

I moved cjsModuleRunnerPlugin to the minimal plugin, to see if that would solve common js issues in the browser example.

I could succesfully load marked and load this context provider from next:

import { PathnameContext } from 'next/dist/shared/lib/hooks-client-context.shared-runtime'

But it gave cryptic messages for some other nextjs modules:

import { AppRouterContext } from 'next/dist/shared/lib/app-router-context.shared-runtime'
import { publicAppRouterInstance } from 'next/dist/client/components/app-router-instance'

The error is:

app-router-context.s...me.js?v=9591181e:35 Uncaught TypeError: Cannot read properties of undefined (reading '_')
 at eval (app-router-context.s...js?v=9591181e:35:57)
 at async ESModulesEvaluator.runInlinedModule (module-runner.js?v=8935b260:905:3)
 at async ModuleRunner.directRequest (module-runner.js?v=8935b260:1112:59)
 at async ModuleRunner.cachedRequest (module-runner.js?v=8935b260:1030:73)
 at async eval (ContextProvider.tsx:6:31)
 at async ESModulesEvaluator.runInlinedModule (module-runner.js?v=8935b260:905:3)
 at async ModuleRunner.directRequest (module-runner.js?v=8935b260:1112:59)
 at async ModuleRunner.cachedRequest (module-runner.js?v=8935b260:1030:73)

It seems that the following module doesn't get loaded correctly:

const _interop_require_default = (await __vite_ssr_dynamic_import__("/@fs/Users/kasperpeulen/code/github/vite-plugin-react/node_modules/.pnpm/@swc+helpers@0.5.15/node_modules/@swc/helpers/esm/_interop_require_default.js?v=9591181e")).default;

So that the _ method is not defined:

const _react = /* @__PURE__ */
 _interop_require_default._((await __vite_ssr_dynamic_import__('/node_modules/.vite/deps_react_client/react.js?v=9591181e').then(m => ( (m2ドル) => m2ドル?.__esModule ? m2ドル : {

@kasperpeulen kasperpeulen changed the title (削除) Example of loading commonjs modules from marked and next (削除ここまで) (追記) Loading commonjs modules in the browser (追記ここまで) Oct 7, 2025
@kasperpeulen kasperpeulen changed the title (削除) Loading commonjs modules in the browser (削除ここまで) (追記) Reproduction of loading commonjs modules from nextjs in the browser (追記ここまで) Oct 7, 2025
Copy link
Contributor

hi-ogawa commented Oct 7, 2025

Thanks for the repro. This looks like one of currently expected bugs in cjsModuleRunnerPlugin. I think some cjs module has require("@swc/helpers") and that's probably transformed to (await import(".../@swc/helpers/esm/...")).default, but this needs to be avoided somehow (probably either import(".../@swc/helpers/esm/...") without default or resolve it to import(".../@swc/helpers/cjs/...") + default).

Copy link
Contributor

hi-ogawa commented Oct 8, 2025

I have fixes two issues #905 #908. Now it looks like vendor/react-server-dom/client.edge.js alias isn't working intended.

Copy link
Contributor

hi-ogawa commented Oct 8, 2025

I appreciate the reproduction PRs. Additionally can you create a tracking issue which points to each reproduction?

kasperpeulen reacted with thumbs up emoji

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /