diff --git a/packages/next-swc/crates/next-core/src/next_import_map.rs b/packages/next-swc/crates/next-core/src/next_import_map.rs
index 87ef801b78415..93572d8a68a90 100644
--- a/packages/next-swc/crates/next-core/src/next_import_map.rs
+++ b/packages/next-swc/crates/next-core/src/next_import_map.rs
@@ -661,6 +661,12 @@ pub async fn insert_next_shared_aliases(
import_map.insert_singleton_alias("react", project_path);
import_map.insert_singleton_alias("react-dom", project_path);
+ //https://github.com/vercel/next.js/blob/f94d4f93e4802f951063cfa3351dd5a2325724b3/packages/next/src/build/webpack-config.ts#L1196
+ import_map.insert_exact_alias(
+ "setimmediate",
+ request_to_import_mapping(project_path, "next/dist/compiled/setimmediate"),
+ );
+
insert_turbopack_dev_alias(import_map);
insert_package_alias(
import_map,
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/client.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/client.tsx
deleted file mode 100644
index 749f91bbf2ffd..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/client.tsx
+++ /dev/null
@@ -1,9 +0,0 @@
-'use client'
-
-export default function Component() {
- return (
-
- {Buffer.from('Hello Client Component', 'utf-8').toString()}
-
- )
-}
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/page.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/page.tsx
deleted file mode 100644
index 64b66b231eb5e..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/page.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import Component from './client'
-
-export default function Page() {
- return (
-
- {Buffer.from('Hello Server Component', 'utf-8').toString()}
-
-
- )
-}
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/layout.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/layout.tsx
deleted file mode 100644
index 12c84680889be..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/layout.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-export default function RootLayout({ children }: { children: any }) {
- return (
-
- {children}
-
- )
-}
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/index.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/index.tsx
deleted file mode 100644
index 7a12e89221ac3..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/index.tsx
+++ /dev/null
@@ -1,58 +0,0 @@
-import { useRef } from 'react'
-import { Harness, useTestHarness } from '@turbo/pack-test-harness'
-
-export default function Page() {
- const pageIframeRef = useRef(null)
- const appIframeRef = useRef(null)
-
- useTestHarness((mod) =>
- runTests(mod, pageIframeRef.current!, appIframeRef.current)
- )
-
- return (
- <>
-
-
- >
- )
-}
-
-function runTests(
- harness: Harness,
- page: HTMLIFrameElement,
- app: HTMLIFrameElement
-) {
- const TIMEOUT = 30000
-
- it(
- 'should support Buffer on pages',
- async () => {
- await harness.waitForLoaded(page)
- const server = await harness.waitForSelector(page, '#server')
- expect(server.innerHTML).toContain('Hello Server Page')
- const client = await harness.waitForSelector(page, '#client')
- expect(client.innerHTML).toContain('Hello Client Page')
- },
- TIMEOUT
- )
-
- it(
- 'should support Buffer on app',
- async () => {
- await harness.waitForLoaded(app)
- const server = await harness.waitForSelector(app, '#server')
- expect(server.innerHTML).toContain('Hello Server Component')
- const client = await harness.waitForSelector(app, '#client')
- expect(client.innerHTML).toContain('Hello Client Component')
- },
- TIMEOUT
- )
-}
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/page.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/page.tsx
deleted file mode 100644
index 675d2052960b8..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/page.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-import { useEffect, useState } from 'react'
-
-export default function Page() {
- const [state, setState] = useState('SSR')
- useEffect(() => {
- setState(
-
- {Buffer.from('Hello Client Page', 'utf-8').toString()}
-
- )
- }, [setState])
- return (
-
-
- {Buffer.from('Hello Server Page', 'utf-8').toString()}
-
- {state}
-
- )
-}
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFile(__q____q____q____star__0__-1ea14a.txt b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFile(__q____q____q____star__0__-1ea14a.txt
deleted file mode 100644
index cb668aa67930e..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFile(__q____q____q____star__0__-1ea14a.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:18:19 lint TP1004 fs.readFile(???*0*) is very dynamic
- 14 | default: obj
- 15 | };
- 16 | }
- 17 | const nodeFs = {
- + v
- 18 + readFile: (f)=>_fs.default.promises.readFile(f),
- + ^
- 19 | readFileSync: (f)=>_fs.default.readFileSync(f),
- 20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
- 21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
- 22 | recursive: true
-
- - *0* f
- ⚠️ pattern without value
\ No newline at end of file
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFile(__q____q____q____star__0__-9b3c3c.txt b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFile(__q____q____q____star__0__-9b3c3c.txt
deleted file mode 100644
index cb668aa67930e..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFile(__q____q____q____star__0__-9b3c3c.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:18:19 lint TP1004 fs.readFile(???*0*) is very dynamic
- 14 | default: obj
- 15 | };
- 16 | }
- 17 | const nodeFs = {
- + v
- 18 + readFile: (f)=>_fs.default.promises.readFile(f),
- + ^
- 19 | readFileSync: (f)=>_fs.default.readFileSync(f),
- 20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
- 21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
- 22 | recursive: true
-
- - *0* f
- ⚠️ pattern without value
\ No newline at end of file
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFileSync(__q____q____q____star_-0b346e.txt b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFileSync(__q____q____q____star_-0b346e.txt
deleted file mode 100644
index e7d760c7e4242..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFileSync(__q____q____q____star_-0b346e.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:19:23 lint TP1004 fs.readFileSync(???*0*) is very dynamic
- 15 | };
- 16 | }
- 17 | const nodeFs = {
- 18 | readFile: (f)=>_fs.default.promises.readFile(f),
- + v
- 19 + readFileSync: (f)=>_fs.default.readFileSync(f),
- + ^
- 20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
- 21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
- 22 | recursive: true
- 23 | }),
-
- - *0* f
- ⚠️ pattern without value
\ No newline at end of file
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFileSync(__q____q____q____star_-c0b6ea.txt b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFileSync(__q____q____q____star_-c0b6ea.txt
deleted file mode 100644
index e7d760c7e4242..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFileSync(__q____q____q____star_-c0b6ea.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:19:23 lint TP1004 fs.readFileSync(???*0*) is very dynamic
- 15 | };
- 16 | }
- 17 | const nodeFs = {
- 18 | readFile: (f)=>_fs.default.promises.readFile(f),
- + v
- 19 + readFileSync: (f)=>_fs.default.readFileSync(f),
- + ^
- 20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
- 21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
- 22 | recursive: true
- 23 | }),
-
- - *0* f
- ⚠️ pattern without value
\ No newline at end of file
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.stat(__q____q____q____star__0__star-05f14f.txt b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.stat(__q____q____q____star__0__star-05f14f.txt
deleted file mode 100644
index 0d33591b07a5f..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.stat(__q____q____q____star__0__star-05f14f.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:24:15 lint TP1004 fs.stat(???*0*) is very dynamic
- 20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
- 21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
- 22 | recursive: true
- 23 | }),
- + v
- 24 + stat: (f)=>_fs.default.promises.stat(f)
- + ^
- 25 | };
- 26 |
- 27 | //# sourceMappingURL=node-fs-methods.js.map
-
- - *0* f
- ⚠️ pattern without value
\ No newline at end of file
diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.stat(__q____q____q____star__0__star-a12dc8.txt b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.stat(__q____q____q____star__0__star-a12dc8.txt
deleted file mode 100644
index 0d33591b07a5f..0000000000000
--- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.stat(__q____q____q____star__0__star-a12dc8.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:24:15 lint TP1004 fs.stat(???*0*) is very dynamic
- 20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
- 21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
- 22 | recursive: true
- 23 | }),
- + v
- 24 + stat: (f)=>_fs.default.promises.stat(f)
- + ^
- 25 | };
- 26 |
- 27 | //# sourceMappingURL=node-fs-methods.js.map
-
- - *0* f
- ⚠️ pattern without value
\ No newline at end of file
diff --git a/test/development/basic/node-builtins/app/layout.js b/test/development/basic/node-builtins/app/layout.js
new file mode 100644
index 0000000000000..8525f5f8c0b2a
--- /dev/null
+++ b/test/development/basic/node-builtins/app/layout.js
@@ -0,0 +1,12 @@
+export const metadata = {
+ title: 'Next.js',
+ description: 'Generated by Next.js',
+}
+
+export default function RootLayout({ children }) {
+ return (
+
+ {children}
+
+ )
+}
diff --git a/test/turbopack-tests-manifest.js b/test/turbopack-tests-manifest.js
index 0dd738906d4d1..fc5e2db345c1a 100644
--- a/test/turbopack-tests-manifest.js
+++ b/test/turbopack-tests-manifest.js
@@ -11,6 +11,7 @@ const enabledTests = [
'test/development/basic/emotion-swc.test.ts',
'test/development/basic/legacy-decorators.test.ts',
'test/development/basic/misc.test.ts',
+ 'test/development/basic/node-builtins.test.ts',
'test/development/basic/next-rs-api.test.ts',
'test/development/basic/tailwind-jit.test.ts',
'test/development/basic/theme-ui.test.ts',