diff --git a/.changeset/loud-planets-breathe.md b/.changeset/loud-planets-breathe.md new file mode 100644 index 0000000000..d99ba3e4e2 --- /dev/null +++ b/.changeset/loud-planets-breathe.md @@ -0,0 +1,5 @@ +--- +"create-t3-app": patch +--- + +get next-auth to work with node 18 diff --git a/cli/src/cli/index.ts b/cli/src/cli/index.ts index 94cbc57ab9..9135ffb812 100644 --- a/cli/src/cli/index.ts +++ b/cli/src/cli/index.ts @@ -133,18 +133,6 @@ export const runCli = async () => { See: https://github.com/t3-oss/create-t3-app/issues/57`); } - // FIXME: TEMPORARY WARNING WHEN USING NODE 18. SEE ISSUE #59 - if (process.versions.node.startsWith("18")) { - logger.warn(` WARNING: You are using Node.js version 18. This is currently not compatible with Next-Auth. - If you want to use Next-Auth, switch to a previous version of Node, e.g. 16 (LTS). - If you have nvm installed, use 'nvm install --lts' to switch to the latest LTS version of Node. - `); - - cliResults.packages = cliResults.packages.filter( - (val) => val !== "nextAuth", - ); - } - // Needs to be separated outside the if statement to correctly infer the type as string | undefined const cliProvidedName = program.args[0]; if (cliProvidedName) { @@ -246,11 +234,6 @@ const promptPackages = async (): Promise => { .map((pkgName) => ({ name: pkgName, checked: false, - // FIXME: TEMPORARY WARNING WHEN USING NODE 18. SEE ISSUE #59 - disabled: - pkgName === "nextAuth" && process.versions.node.startsWith("18") - ? "Node.js version 18 is currently not compatible with Next-Auth." - : false, })), }); diff --git a/cli/src/helpers/installDependencies.ts b/cli/src/helpers/installDependencies.ts index 895e343037..70021f2f7a 100644 --- a/cli/src/helpers/installDependencies.ts +++ b/cli/src/helpers/installDependencies.ts @@ -9,7 +9,24 @@ export const installDependencies = async (projectDir: string) => { const pkgManager = getUserPkgManager(); const spinner = ora(`Running ${pkgManager} install...\n`).start(); - await execa(pkgManager, ["install"], { cwd: projectDir }); + // FIXME: temp fix for next-auth with node 18 + // see: https://github.com/nextauthjs/next-auth/issues/4575 + if ( + process.versions.node.startsWith("18") || + process.versions.node.startsWith("19") + ) { + if (pkgManager === "yarn") { + await execa(pkgManager, ["add", "--ignore-engines", "true"], { + cwd: projectDir, + }); + } else { + await execa(pkgManager, ["install", "--engine-strict", "false"], { + cwd: projectDir, + }); + } + } else { + await execa(pkgManager, ["install"], { cwd: projectDir }); + } spinner.succeed(chalk.green("Successfully installed dependencies!\n")); }; diff --git a/cli/src/installers/nextAuth.ts b/cli/src/installers/nextAuth.ts index b73c9714d4..d16db3d255 100644 --- a/cli/src/installers/nextAuth.ts +++ b/cli/src/installers/nextAuth.ts @@ -46,6 +46,15 @@ export const nextAuthInstaller: Installer = ({ projectDir, packages }) => { "src/types/next-auth.d.ts", ); + // FIXME: temp fix for next-auth with node 18 + // see: https://github.com/nextauthjs/next-auth/issues/4575 + const npmrcSrc = path.join(nextAuthAssetDir, "_npmrc"); + const npmrcDest = path.join(projectDir, ".npmrc"); + const yarnrcSrc = path.join(nextAuthAssetDir, "_yarnrc"); + const yarnrcDest = path.join(projectDir, ".yarnrc"); + fs.copySync(npmrcSrc, npmrcDest); + fs.copySync(yarnrcSrc, yarnrcDest); + fs.copySync(apiHandlerSrc, apiHandlerDest); fs.copySync(getServerAuthSessionSrc, getServerAuthSessionDest); fs.copySync(restrictedApiSrc, restrictedApiDest); diff --git a/cli/template/addons/next-auth/_npmrc b/cli/template/addons/next-auth/_npmrc new file mode 100644 index 0000000000..313a82d22f --- /dev/null +++ b/cli/template/addons/next-auth/_npmrc @@ -0,0 +1 @@ +engine-strict=false \ No newline at end of file diff --git a/cli/template/addons/next-auth/_yarnrc b/cli/template/addons/next-auth/_yarnrc new file mode 100644 index 0000000000..f757a6ac58 --- /dev/null +++ b/cli/template/addons/next-auth/_yarnrc @@ -0,0 +1 @@ +--ignore-engines true \ No newline at end of file