I am trying to deploy the hono example project with nested routes but I keep getting the error below
ReferenceError: exports is not defined in ES module scope
it runs fine locally
Looks like this issue reported here from march hasn’t been resolved
I’ve tested a 2x2x2x2 matrix of factors — JS vs TS, Edge vs Node runtime, dev vs prod, and package.json type: module vs not — and here are the results:
Lang
Runtime
type:module
Dev
Prod
JS
Edge
type:module
JS
Edge
–
JS
Node
type:module
JS
Node
—
TS
Edge
type:module
TS
Edge
—
TS
Node
type:module
TS
Node
—
Error details:
TS/Node/type:module/prod: ReferenceError: exports is not defined in ES module scope
If you’re using any CommonJS modules in your project, you might need to update them to use ES Module syntax or use dynamic imports.
Make sure you’re using a recent version of Node.js that fully supports ES Modules (Node.js 14.x or later is recommended).
If you’re using a bundler like webpack or rollup, ensure it’s configured to handle ES Modules correctly.
If you’re still encountering issues after making these changes, it would be helpful to see more of your code, particularly the file where the error is occurring and any configuration files you’re using.
Hi Paulina, I’ve already done these things. I don’t think you read through my explanation, I’ve linked through the orignal post where he does a much better job of explaining the issue. . There is even a table which points on which instance this doesn’t work.
I found the repro buried in the original thread and passed it along to the team. Thanks for reporting this again.
It only works for me if I build from my local copy and deploy the prebuilt project. So that’s a possible workaround until we can identify the cause and reach a more stable solution.
We’ll keep you updated here as we learn more from the deployment experts
The team just got back to me with the solution. The example repo you shared already had "type": "module" in the the package.json, but no tsconfig.
I copied Pauline’s recommended config from above and my deployment started working as expected. Please make sure you have the project setup so TS files output ES instead of CommonJS. Then the error will go away
I just ran into this issue myself, the culprit is that the Hono starter has the tsconfig in the .vercelignore file so even with the correct settings, it won’t work when you deploy
That’s also why your workaround by building locally worked, since the tsconfig was present in your local system even if it wasn’t being deployed