Skip to content

Commit 3275034

Browse files
Allow next.config.mts for Node.js native TS resolver (#83556)
Following up on #83240 When using ESM syntax in `next.config.ts` on a CJS project, Node.js first assumes it as CJS, then parses it into ESM again, giving a warning: ``` (node:27529) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file://.../next.config.ts is not specified and it doesn't parse as CommonJS. Reparsing as ES module because module syntax was detected. This incurs a performance overhead. To eliminate this warning, add "type": "module" to .../package.json. ``` Therefore, give users the option to use `next.config.mts` which Node.js expects ESM syntax. The tests are a copy of `next-config-ts-native-ts` and only renamed the config to mts. --------- Co-authored-by: Sebastian "Sebbie" Silbermann <[email protected]>
1 parent fd9f0d1 commit 3275034

File tree

112 files changed

+1509
-523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1509
-523
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"plugin:@typescript-eslint/recommended",
6767
"plugin:@typescript-eslint/stylistic"
6868
],
69-
"files": ["**/*.ts", "**/*.tsx"],
69+
"files": ["**/*.ts", "**/*.tsx", "**/*.mts"],
7070
"parser": "@typescript-eslint/parser",
7171
"parserOptions": {
7272
"sourceType": "module",

.github/workflows/build_and_test.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,7 @@ jobs:
561561
with:
562562
nodeVersion: ${{ matrix.node }}
563563
afterBuild: |
564-
export NEXT_TEST_MODE=dev
565-
export NODE_OPTIONS=--experimental-transform-types
566-
node run-tests.js test/e2e/app-dir/next-config-ts-native-ts/**/*.test.ts
564+
NEXT_TEST_MODE=dev NODE_OPTIONS=--experimental-transform-types node run-tests.js test/e2e/app-dir/next-config-ts-native-ts/**/*.test.ts test/e2e/app-dir/next-config-ts-native-mts/**/*.test.ts
567565
stepName: 'test-next-config-ts-native-ts-dev-${{ matrix.node }}'
568566

569567
secrets: inherit
@@ -583,9 +581,7 @@ jobs:
583581
with:
584582
nodeVersion: ${{ matrix.node }}
585583
afterBuild: |
586-
export NEXT_TEST_MODE=start
587-
export NODE_OPTIONS=--experimental-transform-types
588-
node run-tests.js test/e2e/app-dir/next-config-ts-native-ts/**/*.test.ts
584+
NEXT_TEST_MODE=start NODE_OPTIONS=--experimental-transform-types node run-tests.js test/e2e/app-dir/next-config-ts-native-ts/**/*.test.ts test/e2e/app-dir/next-config-ts-native-mts/**/*.test.ts
589585
stepName: 'test-next-config-ts-native-ts-prod-${{ matrix.node }}'
590586

591587
secrets: inherit

packages/create-next-app/templates/app-api/ts/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"@/*": ["./*"]
2323
}
2424
},
25-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
25+
"include": [
26+
"next-env.d.ts",
27+
"**/*.ts",
28+
"**/*.tsx",
29+
".next/types/**/*.ts",
30+
"**/*.mts"
31+
],
2632
"exclude": ["node_modules"]
2733
}

packages/create-next-app/templates/app-empty/ts/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"@/*": ["./*"]
2323
}
2424
},
25-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
25+
"include": [
26+
"next-env.d.ts",
27+
"**/*.ts",
28+
"**/*.tsx",
29+
".next/types/**/*.ts",
30+
"**/*.mts"
31+
],
2632
"exclude": ["node_modules"]
2733
}

packages/create-next-app/templates/app-tw-empty/ts/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"@/*": ["./*"]
2323
}
2424
},
25-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
25+
"include": [
26+
"next-env.d.ts",
27+
"**/*.ts",
28+
"**/*.tsx",
29+
".next/types/**/*.ts",
30+
"**/*.mts"
31+
],
2632
"exclude": ["node_modules"]
2733
}

packages/create-next-app/templates/app-tw/ts/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"@/*": ["./*"]
2323
}
2424
},
25-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
25+
"include": [
26+
"next-env.d.ts",
27+
"**/*.ts",
28+
"**/*.tsx",
29+
".next/types/**/*.ts",
30+
"**/*.mts"
31+
],
2632
"exclude": ["node_modules"]
2733
}

packages/create-next-app/templates/app/ts/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"@/*": ["./*"]
2323
}
2424
},
25-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
25+
"include": [
26+
"next-env.d.ts",
27+
"**/*.ts",
28+
"**/*.tsx",
29+
".next/types/**/*.ts",
30+
"**/*.mts"
31+
],
2632
"exclude": ["node_modules"]
2733
}

packages/create-next-app/templates/default-empty/ts/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
"@/*": ["./*"]
1818
}
1919
},
20-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
20+
"include": [
21+
"next-env.d.ts",
22+
"**/*.ts",
23+
"**/*.tsx",
24+
".next/types/**/*.ts",
25+
"**/*.mts"
26+
],
2127
"exclude": ["node_modules"]
2228
}

packages/create-next-app/templates/default-tw-empty/ts/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
"@/*": ["./*"]
1818
}
1919
},
20-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
20+
"include": [
21+
"next-env.d.ts",
22+
"**/*.ts",
23+
"**/*.tsx",
24+
".next/types/**/*.ts",
25+
"**/*.mts"
26+
],
2127
"exclude": ["node_modules"]
2228
}

packages/create-next-app/templates/default-tw/ts/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
"@/*": ["./*"]
1818
}
1919
},
20-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
20+
"include": [
21+
"next-env.d.ts",
22+
"**/*.ts",
23+
"**/*.tsx",
24+
".next/types/**/*.ts",
25+
"**/*.mts"
26+
],
2127
"exclude": ["node_modules"]
2228
}

0 commit comments

Comments
 (0)