Skip to content

Commit

Permalink
Create a package.json with type: "commonjs" in .next/server (vercel#145)
Browse files Browse the repository at this point in the history
Closes vercel#109

Note a difference between this and stable Next.js: at turbopack this
file is placed in .next/server/package.json, while Next.js currently
creates this file at .next/package.json.

Test Plan: Verified that the `hello-world-esm` no longer fails to SSR
(it's now blocked by vercel#111).

Co-authored-by: Tobias Koppers <[email protected]>
  • Loading branch information
wbinnssmith and sokra authored Oct 21, 2022
1 parent 93db83e commit 2077e0c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/next-core/src/nodejs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use turbopack::ecmascript::EcmascriptModuleAssetVc;
use turbopack_core::{
asset::{Asset, AssetContentVc, AssetVc, AssetsSetVc},
chunk::{ChunkGroupVc, ChunkingContextVc},
virtual_asset::VirtualAssetVc,
};
use turbopack_dev_server::{
html::DevHtmlAssetVc,
Expand Down Expand Up @@ -177,7 +178,24 @@ async fn get_renderer_pool(
intermediate_asset: AssetVc,
intermediate_output_path: FileSystemPathVc,
) -> Result<NodeJsPoolVc> {
// Emit a basic package.json that sets the type of the package to commonjs.
// Currently code generated for Node is CommonJS, while authored code may be
// ESM, for example.
//
// Note that this is placed at .next/server/package.json, while Next.js
// currently creates this file at .next/package.json.
emit(
VirtualAssetVc::new(
intermediate_output_path.join("package.json"),
FileContent::Content(File::from("{\"type\": \"commonjs\"}")).into(),
)
.into(),
intermediate_output_path,
)
.await?;

emit(intermediate_asset, intermediate_output_path).await?;

let output = intermediate_output_path.await?;
if let Some(disk) = DiskFileSystemVc::resolve_from(output.fs).await? {
let dir = PathBuf::from(&disk.await?.root).join(&output.path);
Expand Down

0 comments on commit 2077e0c

Please sign in to comment.