Skip to content

Commit

Permalink
fix: next-auth doesn't install when using node 18 (t3-oss#642)
Browse files Browse the repository at this point in the history
* node 18 next-auth engines fix

* chore: add changeset

* also check for node 19

Co-authored-by: Julius Marminge <[email protected]>

Co-authored-by: Julius Marminge <[email protected]>
  • Loading branch information
c-ehrlich and juliusmarminge committed Oct 23, 2022
1 parent 9976c54 commit 9403432
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-planets-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

get next-auth to work with node 18
17 changes: 0 additions & 17 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -246,11 +234,6 @@ const promptPackages = async (): Promise<AvailablePackages[]> => {
.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,
})),
});

Expand Down
19 changes: 18 additions & 1 deletion cli/src/helpers/installDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
};
9 changes: 9 additions & 0 deletions cli/src/installers/nextAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions cli/template/addons/next-auth/_npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=false
1 change: 1 addition & 0 deletions cli/template/addons/next-auth/_yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--ignore-engines true

0 comments on commit 9403432

Please sign in to comment.