Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: top level await breaks next.js with typescript template #7665

Open
beratbayram opened this issue Jan 4, 2025 · 1 comment
Open
Labels
bug Something that isn't working

Comments

@beratbayram
Copy link

beratbayram commented Jan 4, 2025

Which Cloudflare product(s) does this pertain to?

C3 (npm create cloudflare)

What versions are you using?

2.35.1 [C3 - create-cloudflare@latest]

What operating system and version are you using?

Mac Sequoia 15.2

Please provide a link to a minimal reproduction

No response

Describe the Bug

npm create cloudflare@latest . --framework=next

create-cloudflare creates a next.js project with a top-level await in the config file. If typescript is selected, it causes a problem because top-level await can only be used inside a .mts or .mjs file, but the Next config is a .ts file and can't be a .mts file(1). A simple npm run dev causes:

ReferenceError: await is not defined

There is no problem if javascript is selected because next config is a .mjs file.

There is no problem if JavaScript is selected because the Next config is a .mjs file. I have proposed a solution at this comment. But the code block below says awaiting may not be necessary, so maybe we can delete the await and be done with it. In any case, the template engine should not output an invalid configuration.

if (process.env.NODE_ENV === 'development') {
	// `await`ing the call is not necessary but it helps making sure that the setup has succeeded.
	//  If you cannot use top level awaits you could use the following to avoid an unhandled rejection:
	//  `setupDevPlatform().catch(e => console.error(e));`
	await setupDevPlatform();
}

From: https://github.com/cloudflare/next-on-pages/blob/main/internal-packages/next-dev/README.md

If you give me directions, I can open a PR.

Please also see other issues at the next-on-pages repo with the same problem:

cloudflare/next-on-pages#927
cloudflare/next-on-pages#925

Please provide any relevant error logs

No response

@dario-piotrowicz
Copy link
Member

Hi @beratbayram 🙂

Thanks for the issue and sorry for the late reply I just only now noticed it

Given this problem I think C3 should create a next.config.mjs file instead and use jsdocs for types, exactly how you did it here: cloudflare/next-on-pages#925 (comment)

Would you like to open a PR with this change? 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Untriaged
Development

No branches or pull requests

2 participants