-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(remix-dev/vite): preserve named exports when emptifying server/client only files #7973
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
Conversation
🦋 Changeset detectedLatest commit: eb2f7cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
Patching Context:
|
|
@gustavopch Thanks for testing this patch! However, I'm suspecting the issue you are seeing with I tested basic setup on current remix vite (so without this PR's patch) https://stackblitz.com/edit/remix-run-remix-ikymah?file=app%2Futils.ts. First, I can also see I think what's odd is that which itself is fine and a common thing to do, but these two modules are "incompatible" in ESM sense since these two files exports different names (e.g. client one is missing |
|
@hi-ogawa Thanks for investigating and sharing the repro on StackBlitz. 🙏 I've opened an issue there: getsentry/sentry-javascript#9594. |
|
Superceded by #8200 Specifically, we want any @hi-ogawa thanks for your work on this! Adapted your code for preserving |

Closes: #7924, #7972
Based on the idea mentioned in #7924 (comment), I updated
"remix-empty-server-modules"and"remix-empty-client-modules"to preserve named exports.(It's worth noting that this won't probably fix #7957 since that issue is more related to
"remix-remove-server-exports"plugin.)I'm not sure if this approach is foolproof, but I thought it would be better to put together a PR to convey the idea clearly.
I would appreciate any feedback. Thanks!
note 1
One notable (and maybe critical) difference from simple
export default {}is that, this will now potentially expose the export names from server only files in client assets if rollup didn't tree shake named exports.I was thinking to keep using
export default {}forbuildcase, but it turns out rollup checks export names and throws an following error, so this approach might not be robust:rollup error
As one more important factor to decide on this, I think it's worth noting that vite build has
minify: trueby default, so probably for most practical purposes, we can assume that original names won't be visible directly on client.Here are the examples of client assets output with corresponding minfiy flags:
minify: true (default)
minify: false
note 2
I also noticed that pre-vite remix applies "empifying" transform only for user application code, but vite version currently applies to all files including
node_modules.remix/packages/remix-dev/compiler/plugins/emptyModules.ts
Lines 21 to 26 in eb2f7cb
I'm not sure if this change was intentional, but if it's still meant to be applied only for user code, then I think we could add additional check such as
id.startsWith(cachedPluginConfig.appDirectory).