-
Notifications
You must be signed in to change notification settings - Fork 131
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]: Typescript transpilation error with clean Next.js template #925
Comments
A potential fix could be to remove the await. Based on the
This actually fixes the problem, but I am not sure if it creates other side effects. |
A workaround is to use Async Configuration import type { NextConfig } from "next";
const nextConfig: () => Promise<NextConfig> = async () => {
// Here we use the @cloudflare/next-on-pages next-dev module to allow us to use bindings during local development
// (when running the application with `next dev`), for more information see:
// https://github.com/cloudflare/next-on-pages/blob/main/internal-packages/next-dev/README.md
if (process.env.NODE_ENV === "development") {
const { setupDevPlatform } = await import(
"@cloudflare/next-on-pages/next-dev"
);
await setupDevPlatform();
}
return {
/* config options here */
};
};
export default nextConfig; |
Top-level await requires an es-module file (aka .mjs or .mts). Since Next does not support .mts for the config file (1), a simple workaround would be to change the file name to next.config.mjs and the content to: import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev';
// Here we use the @cloudflare/next-on-pages next-dev module to allow us to use
// bindings during local development (when running the application with
// `next dev`), for more information see:
// https://github.com/cloudflare/next-on-pages/blob/main/internal-packages/next-dev/README.md
if (process.env.NODE_ENV === 'development') {
await setupDevPlatform();
}
/** @type {import('next').NextConfig} */
const nextConfig = {
/* config options here */
};
export default nextConfig; I haven't tested it much but it seems to be working. |
fix npm run dev. cloudflare/next-on-pages#925
@beratbayram thank you for this!
|
next-on-pages environment related information
System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.2.0: Fri Dec 6 19:01:59 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6000
CPU: (10) arm64 Apple M1 Max
Memory: 64 GB
Shell: /bin/zsh
Package Manager Used: npm (10.9.0)
Relevant Packages:
@cloudflare/next-on-pages: 1.13.7
vercel: N/A
next: N/A
Description
With a clean, newly created next-on-pages
pnpm run dev
raises this error only if Typescript is enabled:Reproduction
pnpm create cloudflare@latest cpshomeweb --framework=next
with the following options:Pages Deployment Method
Direct Upload (
wrangler pages publish
or the @cloudflare/pages-action GitHub Action)Pages Deployment ID
No response
Additional Information
No response
Would you like to help?
The text was updated successfully, but these errors were encountered: