-
Notifications
You must be signed in to change notification settings - Fork 20
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
Use import
instead of require
to fix ESM Remix apps
#29
base: main
Are you sure you want to change the base?
Conversation
So I eventually want to move to using remix vite, but I am interested in a short term fix for this before that happens (since it's not trivial, lol) I think the approach I'd want to take is something like this: try {
await import(...)
} catch (importError) {
try {
require(...)
} catch (requireError) {
console.error("Failed to load build.", { importError, requireError })
}
} If you can update this PR and ensure it works for both CJS and ESM projects, I'd be happy to merge this and release! |
@itsMapleLeaf not sure we need the try/catch thing. Dynamic imports are allowed in CJS right?
remix-electron/workspaces/remix-electron/src/index.mts Lines 45 to 48 in 44d87c6
Nonetheless I will try to scaffold a CJS app and test this version with imports.
What we need is a timestamp on the statements to invalidate the cache. With that we can remove the Eg. await import(`${buildPath}?${Date.now()}`); Happy to make those changes if you agree (I have this in my fork and it works). |
@giuseppeg Sure, sounds good to me. I'm not concerned about the implementation details, just that both CJS and ESM projects work 👍 |
@itsMapleLeaf implemented all the changes in #33 I added a ESM test app too |
This is a (partial) fix for #28.
You might want to just use it as inspiration since this won't work for the
.cjs
build of this package. Or maybe it's time to drop the.cjs
build, considering the Remix templates are ESM at this point.I also didn't try the dev mode, but I'm sure the purging of the require cache doesn't work correctly with this change. Not sure how to do that when using
import
(nodejs/node#49442).