next.js
8a8888ca - [turbopack] use `require` to load chunks in our node runtime (#81738)

Commit
163 days ago
[turbopack] use `require` to load chunks in our node runtime (#81738) ## Use `require` to load chunks in node instead of readFile+eval The benefit of this is that we can slightly simplify chunk loading and make it easier for hosting services to cache bytecode. Much like [browsers](https://v8.dev/blog/code-caching-for-devs), server environments often leverage VM features to cache parsed javascript as bytecode (or maybe binary ast?) to accelerate cold starts ([example](https://vercel.com/blog/introducing-bytecode-caching-for-vercel-functions)), however, these systems generally avoid caching highly dynamic content like inline scripts and `eval` parameters. So just use `require` which is what platforms expect! This should help platforms achieve code caching, is generally simpler, and by not adding a prefix we fix some subtle off-by-one issue with source maps. A slightly better solution imho would be `import()` since it would enable node to do some file reading parsing async with the main thread which could be important if there are multiple `preloadModules`, however this breaks dev mode hot reloading. Fixes #PACK-5062
Author
Parents
Loading