-
Notifications
You must be signed in to change notification settings - Fork 2
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
Don't throw unreplaced macro
when running without Vite
#19
Comments
Originally, I hesitated to implement this feature since it felt like the error provided a base layer of safety. An alternative I thought of was to have Another option would be to have a So to summarize, I think you're right that a simple runtime check for Vite is the best approach. If you are using the Vite plugin, things continue to work the same way. If you aren't using the Vite plugin, there's no bundling going on so there's no module graph artifact to try to protect in the first place. |
@pcattori Hey, any chance the original changes in the PR you made can be merged? I see you proposed a smarter solution, but perhaps this check is good enough to merge? My team has the same problem, we are including some share code in our unit tests which triggers this error. We have been mitigating this by using |
We are also hitting this issue, we have some code shared between our expressjs remix server and the remix bundle itself. The expressjs code is compiled with esbuild and therefore throws when using the same code, since there is no Vite plugin to remove the $serverOnly macros. A solution that ensures $serverOnly doesn't throw when built outside of Vite such as with esbuild would be great. |
@jrestall Besides the patch I provided in the first message, you can also work around by moving as much of your Express server code to the bundle as possible as described here: remix-run/remix#9790 (reply in thread) |
Really appreciate the tip @gustavopch, thank you! Moving all our expressjs server code to entry.server would be a very large change across our apps but it's good to know there's another option. We'll go with the patch for now and hope the behavior is fixed. |
Is there a temporary workaround? Or do we have to build from source with the patch? I don't see why we would care about people not using vite. The plugin is called |
@zwhitchcox You don't need to build from source to patch. You can use https://npm.im/package/patch-package or something similar. |
@gustavopch Thanks! |
hitting this issue with playwright running e2e with dev server. |
I am using
serverOnly$
to ensure Vite doesn't bundle a function that's supposed to be executed on the server. But I actually also need to run that function in a simple Node.js script that doesn't use Vite. When I run my script, I get this error:So I propose that that error is only thrown when running via Vite.
Not sure if there's a better way to check, but possibly something like this:
The text was updated successfully, but these errors were encountered: