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

feat(resolve): auto externalize node builtins for noExternal: true in node #16019

Merged
merged 3 commits into from Mar 12, 2024

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Feb 23, 2024

Description

In this PR, when setting ssr.noExternal: true and ssr.target: 'node' (default), node builtins will be auto-externalized. Without this PR, it'll error that Cannot bundle Node.js built-in "node:http" imported from .... Consider disabling ssr.noExternal or remove the built-in dependency., which I think is odd because we know we're building for node, and it's safe to auto-externalize by default.

This feature was added long ago in #4490 for webworkers. And there's also workarounds by setting node builtins in ssr.external manually yourself. But I figured to kick off this idea since it feels like a safe default.

Additional context

Found this while reviewing withastro/astro#10202. I figured for users who build to node and want to bundle everything, we can suggest ssr.noExternal: true only and it'll work, otherwise they need to workaround setting builtins in ssr.external manually.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines, especially the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Update the corresponding documentation if needed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bluwy bluwy added p2-nice-to-have Not breaking anything but nice to have (priority) feat: ssr labels Feb 23, 2024
Copy link

stackblitz bot commented Feb 23, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@bluwy bluwy merged commit 1cc88c1 into main Mar 12, 2024
11 checks passed
@bluwy bluwy deleted the no-external-true-node branch March 12, 2024 13:15
@acoderacom
Copy link

just update to 5.2.2 but still got error
12:57:19 AM: Error [RollupError]: [commonjs--resolver] Cannot bundle Node.js built-in "node:crypto" imported from "node_modules/@remix-run/node/dist/sessions/fileStorage.js". Consider disabling ssr.noExternal or remove the built-in dependency.

@bluwy
Copy link
Member Author

bluwy commented Mar 21, 2024

Can you open a new issue and repro for it? I'm pretty sure this PR is working correctly

@acoderacom
Copy link

no worry, I was able to fix it. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants