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] Auto generated open-next.config.ts is invalid #427

Closed
timReynolds opened this issue Feb 28, 2025 · 6 comments · Fixed by #429 · May be fixed by #428
Closed

[BUG] Auto generated open-next.config.ts is invalid #427

timReynolds opened this issue Feb 28, 2025 · 6 comments · Fixed by #429 · May be fixed by #428
Assignees
Labels
question Further information is requested

Comments

@timReynolds
Copy link

Describe the bug

While playing with opennextjs/cloudflare I decided to following the manual instructions found here which in step 4. highlights its optional and will be auto generated.

However when auto generating the file via npm run preview I get an errors, the code added to the new file open-next.config.ts is as follows inline with the documentation;

// default open-next.config.ts file created by @opennextjs/cloudflare
import { defineCloudflareConfig } from "@opennextjs/cloudflare/dist/api/config";
import kvIncrementalCache from "@opennextjs/cloudflare/dist/api/kv-cache";

export default defineCloudflareConfig({
  incrementalCache: kvIncrementalCache,
});

However if I was to look at a project created using npm create cloudflare@latest -- my-next-app --framework=next --experimental it would be as follows;

import cache from "@opennextjs/cloudflare/kvCache";

const config = {
  default: {
    override: {
      wrapper: "cloudflare-node",
      converter: "edge",
      incrementalCache: async () => cache,
      tagCache: "dummy",
      queue: "dummy",
    },
  },
  middleware: {
    external: true,
    override: {
      wrapper: "cloudflare-edge",
      converter: "edge",
      proxyExternalRequest: "fetch",
    },
  },
  dangerous: {
    enableCacheInterception: false,
  },
};

export default config;

Steps to reproduce

  1. Follow the get started guide found https://opennext.js.org/cloudflare/get-started not creating optional files
  2. Run npm run preview after step 6

Expected behavior

Preview starts after valid config is added

@opennextjs/cloudflare version

0.5.6

Wrangler version

3.111.0

next info output

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.4.0: Sat Feb 15 22:49:30 PST 2025; root:xnu-11417.100.533.501.4~3/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 22.12.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.15.2
Relevant Packages:
  next: 15.2.0 // Latest available version is detected (15.2.0).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.8.2
Next.js Config:
  output: N/A

Additional context

No response

@vicb
Copy link
Contributor

vicb commented Feb 28, 2025

However when auto generating the file via npm run preview I get an errors, the code added to the new file open-next.config.ts is as follows inline with the documentation;

What do you mean by "I get an errors"? Do you get a crash?

defineCloudflareConfigwas recently introduced and @dario-piotrowicz will update the template soon.

@JasonGiedymin
Copy link

JasonGiedymin commented Feb 28, 2025

He most likely gets the following:

┌─────────────────────────────┐
│ OpenNext — Cloudflare build │
└─────────────────────────────┘

✘ [ERROR] Could not resolve "@opennextjs/cloudflare/dist/api/config"

    open-next.config.ts:2:39:
      2 │ import { defineCloudflareConfig } from "@opennextjs/cloudflare/dist/api/config";~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The module "./dist/api/dist/api/config.js" was not found on the file system:

    node_modules/@opennextjs/cloudflare/package.json:18:16:
      18 │       "import": "./dist/api/*.js",
         ╵                 ~~~~~~~~~~~~~~~~~

  You can mark the path "@opennextjs/cloudflare/dist/api/config" as external to exclude it from the
  bundle, which will remove this error.

✘ [ERROR] Could not resolve "@opennextjs/cloudflare/dist/api/kv-cache"

    open-next.config.ts:3:31:
      3 │ import kvIncrementalCache from "@opennextjs/cloudflare/dist/api/kv-cache";~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The module "./dist/api/dist/api/kv-cache.js" was not found on the file system:

    node_modules/@opennextjs/cloudflare/package.json:18:16:
      18 │       "import": "./dist/api/*.js",
         ╵                 ~~~~~~~~~~~~~~~~~

  You can mark the path "@opennextjs/cloudflare/dist/api/kv-cache" as external to exclude it from
  the bundle, which will remove this error.

node:internal/modules/run_main:122
    triggerUncaughtException(
    ^

Error: Build failed with 2 errors:
open-next.config.ts:2:39: ERROR: Could not resolve "@opennextjs/cloudflare/dist/api/config"
open-next.config.ts:3:31: ERROR: Could not resolve "@opennextjs/cloudflare/dist/api/kv-cache"

@timReynolds
Copy link
Author

@JasonGiedymin is correct. Those are the errors I was seeing

@vicb
Copy link
Contributor

vicb commented Feb 28, 2025

@dario-piotrowicz can you please take a look?

@vicb
Copy link
Contributor

vicb commented Feb 28, 2025

Can you try to change:

// before
import { defineCloudflareConfig } from "@opennextjs/cloudflare/dist/api/config";
import kvIncrementalCache from "@opennextjs/cloudflare/dist/api/kv-cache";
// after
import { defineCloudflareConfig } from "@opennextjs/cloudflare/config";
import kvIncrementalCache from "@opennextjs/cloudflare/kv-cache";

@vicb
Copy link
Contributor

vicb commented Feb 28, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
4 participants