opennextjs / opennextjs-cloudflare

Open Next.js adapter for Cloudflare
https://opennext.js.org/cloudflare
MIT License
378 stars 8 forks source link

Error: Not in a Next.js app project #82

Closed megaconfidence closed 1 month ago

megaconfidence commented 1 month ago

I'm trying to deploy this Nextjs template on Workers using opennext but I get this error

https://vercel.com/templates/next.js/empathic-voice-interface-starter https://vercel.com/templates/next.js/blog-starter-kit

Building the Next.js app in the current folder (/Users/megaconfidence/Sandbox/temp/hume-evi-next-js-starter)
file:///Users/megaconfidence/Sandbox/temp/hume-evi-next-js-starter/node_modules/@opennextjs/cloudflare/dist/cli/index.mjs:7291
  throw new Error("Error: Not in a Next.js app project");
        ^

Error: Error: Not in a Next.js app project
    at file:///Users/megaconfidence/Sandbox/temp/hume-evi-next-js-starter/node_modules/@opennextjs/cloudflare/dist/cli/index.mjs:7291:9
    at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)

Node.js v20.17.0
shashankboosi commented 1 month ago

Hey @megaconfidence,

You are getting the issue because the adapter only supports next projects which have the next.config file. If the adapter doesn't find it, will throw the error. So to fix your issue add the next.config file. I have posted the bare minimum code with defaults below

/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;

I have raised a PR to add a detailed error going forward for other users. I hope this helps!

cc @vicb

vicb commented 1 month ago

@shashankboosi Thank you so much for your help!

megaconfidence commented 1 month ago

Thanks @shashankboosi. I've added the config file and local dev in Nodejs works. But when I try to build for Workerd with preview:workers, I get the following error in the browser:

Here's a link to my project https://github.com/megaconfidence/next-blog-starter-worker

image
vicb commented 1 month ago

@shashankboosi both improved the error message and also added the blog starter app, see #86 It will be merged on the feedback is adressed

shashankboosi commented 1 month ago

Hey @megaconfidence,

As @vicb said, the PR mentioned should work and it is night time here. So will try to get the PR ready for merge tomorrow. Play around with the PR till then :)

megaconfidence commented 1 month ago

Thanks, everything seems to work as expected in the PR. Thanks for working on this