denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.47k stars 5.33k forks source link

"deno install" breaks fresh Next.js project on Deno 2 #26166

Open Janhouse opened 1 week ago

Janhouse commented 1 week ago

Deno 2 is not usable with Next.js because next stops building as soon as deno install is run for the first time in fresh project even without adding any new npm modules.

Version: Deno 2.0.0

deno run -A npm:create-next-app@latest .
deno run -A build
# This works and Next.js builds

# Immediately after run

deno install
deno run -A build
# This fails with `..Error: Cannot find module './chunks/379.js'`
# Deleting `node_modules` and `deno.lock` does not help
Janhouse commented 1 week ago

Here is terminal recording of it:

asciicast

nathanwhit commented 1 week ago

Try deleting the .next folder and then rebuilding (you may want to delete node_modules and re-run deno install to be safe, but I think it shouldn’t be necessary.


I believe the issue is that in this case, create-next-app first runs a npm install. When you do the first build, next caches the results, and the cache is dependent on the exact layout of the node_modules folder. Then, when you run deno install the node_modules folder is updated, and the new layout breaks the cached build.

We plan on upstreaming a PR to next to use deno install instead of npm when running in deno, which would fix this. Aside from that, I'll see if we could provide a better diagnostic here to prevent this confusing situation

ashishk15678 commented 1 day ago

Hi , Is the issue fixed or it still persists ?