diff --git a/.changeset/tasty-teachers-lick.md b/.changeset/tasty-teachers-lick.md new file mode 100644 index 000000000000..06d478c33886 --- /dev/null +++ b/.changeset/tasty-teachers-lick.md @@ -0,0 +1,5 @@ +--- +"create-cloudflare": patch +--- + +fix the generation of invalid/incorrect scripts for Next.js applications diff --git a/packages/create-cloudflare/src/frameworks/next/index.ts b/packages/create-cloudflare/src/frameworks/next/index.ts index ca56f7231fbe..e5594d1bf281 100644 --- a/packages/create-cloudflare/src/frameworks/next/index.ts +++ b/packages/create-cloudflare/src/frameworks/next/index.ts @@ -141,12 +141,20 @@ const config: FrameworkConfig = { generate, configure, displayName: "Next", - getPackageScripts: async () => ({ - "pages:build": `${dlx} @cloudflare/next-on-pages@1`, - "pages:deploy": `${npm} run pages:build && wrangler pages deploy .vercel/output/static`, - "pages:watch": `${npx} @cloudflare/next-on-pages@1 --watch`, - "pages:dev": `${npx} wrangler pages dev .vercel/output/static ${await compatDateFlag()} --compatibility-flag=nodejs_compat`, - }), + getPackageScripts: async () => { + const isNpmOrBun = ["npm", "bun"].includes(npm); + const nextOnPagesScope = isNpmOrBun ? "@cloudflare/" : ""; + const nextOnPagesCommand = `${nextOnPagesScope}next-on-pages`; + const pmCommand = isNpmOrBun ? npx : npm; + return { + "pages:build": `${pmCommand} ${nextOnPagesCommand}`, + "pages:deploy": `${ + npm === "npm" ? "npm run" : pmCommand + } pages:build && wrangler pages deploy .vercel/output/static`, + "pages:watch": `${pmCommand} ${nextOnPagesCommand} --watch`, + "pages:dev": `${pmCommand} wrangler pages dev .vercel/output/static ${await compatDateFlag()} --compatibility-flag=nodejs_compat`, + }; + }, testFlags: [ "--typescript", "--no-install",