Skip to content
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

Module not found: Can't resolve '_http_common' #70262

Closed
kettanaito opened this issue Sep 19, 2024 · 3 comments · Fixed by #70382
Closed

Module not found: Can't resolve '_http_common' #70262

kettanaito opened this issue Sep 19, 2024 · 3 comments · Fixed by #70382
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc. linear: next Confirmed issue that is tracked by the Next.js team. locked Runtime Related to Node.js or Edge Runtime with Next.js. Webpack Related to Webpack with Next.js.

Comments

@kettanaito
Copy link
Contributor

kettanaito commented Sep 19, 2024

Link to the code that reproduces this issue

mswjs/msw#2291

To Reproduce

Please follow the reproduction steps in the linked issue above.

Current vs. Expected behavior

Current

Next.js throws an error, unable to import a built-in _http_common module in Node.js.

Expectd

Next.js properly imports the built-in module.

Provide environment information

Irrelevant, this is a webpack configuration issue.

Which area(s) are affected? (Select all that apply)

Developer Experience, Runtime, Webpack

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed)

Additional context

I believe this is caused by the Next's default webpack config not listing _http_common in config.externals.

Any thoughts on listing all built-in Node.js modules as external?

{
  // All built-in modules in Node.js must be treated as external.
  externals: require('module').builtinModules
}

I'm proposing this because contributors report that adding _http_common into config.externals helps them. This should be handled on Next's side.

@kettanaito kettanaito added the bug Issue was opened via the bug report template. label Sep 19, 2024
@github-actions github-actions bot added Developer Experience Issues related to Next.js logs, Error overlay, etc. Runtime Related to Node.js or Edge Runtime with Next.js. Webpack Related to Webpack with Next.js. labels Sep 19, 2024
@vishakha94
Copy link

vishakha94 commented Sep 20, 2024

Facing the same issue with the NextJS and MSW setup.
Node: v20.17.0
MSW: v2.4.8

Screenshot 2024-09-20 at 12 03 30 PM

I am able to unblock myself with downgrading to MSW v2.4.3 for now

@kettanaito
Copy link
Contributor Author

@vishakha94, that's expected since the newest versions of MSW rely on the built-in HTTPParser in Node.j to parse outgoing Socket packets. I haven't experienced this issue when working with other frameworks. The _http_common import must be configured correctly on Next's side as external because it's a built-in module. Looks like webpack is trying to import it from your node_modules, and fails in the process.

@ztanner ztanner pinned this issue Sep 20, 2024
@samcx samcx unpinned this issue Sep 20, 2024
@ztanner ztanner added the linear: next Confirmed issue that is tracked by the Next.js team. label Sep 23, 2024
ijjk pushed a commit that referenced this issue Sep 24, 2024
We should not attempt to bundle builtin node modules on the server. This
adds modules provided by Node.js to our externals list (along with some
missing internal ones in Turbopack. These were copied from
[here](https://github.com/vercel/next.js/blob/a675bde6c738318264573144663e38819aeb2661/crates/next-custom-transforms/src/transforms/warn_for_edge_runtime.rs#L77-L89)).

Fixes #70262
Closes NDX-314
# Conflicts:
#	turbopack/crates/turbopack-resolve/src/resolve.rs
mina-gwak added a commit to plus-82/plus82.front that referenced this issue Oct 3, 2024
Copy link
Contributor

github-actions bot commented Oct 8, 2024

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Oct 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc. linear: next Confirmed issue that is tracked by the Next.js team. locked Runtime Related to Node.js or Edge Runtime with Next.js. Webpack Related to Webpack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants