remix: remix-serve is incompatible with serverModuleFormat:esm
What version of Remix are you using?
v1.16.0
Are all your remix dependencies & dev-dependencies using the same version?
- Yes
Steps to Reproduce
Set the serverModuleFormat to esm and run the server
Expected Behavior
Run without any issues
Actual Behavior
Getting the SyntaxError: Cannot use import statement outside a module from the build/index.js


About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 26
- Comments: 17 (3 by maintainers)
Same issue here on
1.16.0. SettingserverModuleFormattoesm, I receive:Hey folks! We probably could have communicated this a bit better but at the moment these errors will depend on the server you’re using. I’m going to keep this issue open for tracking
@remix-run/servecompatibility with ESM as we prep for v2.Remix App Server
@remix-run/serveis not compatible withserverModuleFormat: "esm"in v1 because that would be a breaking change. Once v2 is released, it will be compatible withserverModuleFormat: "esm".For now, if you are using
@remix-run/serveyou should setserverModuleFormat: "cjs"in yourremix.config.jsto explicitly indicate your app setting which will silence the warning and ensure your app is able to upgrade to v2 without issues.Express Template
If folks are running into issues with the
expresstemplate, these should be the steps you need to follow to convert a CJSexpressapp to an ESMexpressapp:serverModuleFormat: "esm"inremix.config.jstype:"module"to yourpackage.jsonimportinstead ofrequire)purgeRequireCacheimplementation in the default express template relies on CJS so you won’t be able to use that functionality and your server will not receive updates without a restartnode --watchornodemonto auto-restart on changes.remix.config.jsto be an ESM module (i.e.,export defaultinstead ofmodule.exports).eslintrc.js -> .eslintrc.cjsbecause ESLint doesn’t support an ESM config filev2 Express Template
You can also create a brand new Remix app with Express + ESM using our eventual v2 template for Express via the following:
Can also confirm this seems broken. If you add
type: moduleto the package.json and converting remix.config,js to ES module doesn’t work either as@remix-run/serveuses require() to get the build.Only fix I could find was changing serverModuleFormat back to cjs in remix config
@jacob-ebey just tried upgrading all my
@remix-run/*dependencies to thenightlytag. However, I’m still seeing the[ERR_REQUIRE_ESM]issue 😕.Add it to your server dependencies: https://remix.run/docs/en/1.16.1/pages/gotchas#importing-esm-packages
That branch has been merged to
dev, you can now runYou may also need to install
@remix-run/serveas adevDependencyin the created app.