`wix/astro` incompatible with Astro 6 + Cloudflare — `require is not defined` in workerd

I’m having trouble with
Executing a new wix app running npm run dev.

Working in
Dev Mode

Environment:

  • Astro: 6.1.5
  • [at]astrojs/cloudflare: 13.1.8
  • [at]wix/astro: 2.13.0
  • Node: (v24.15.0)

Description:
I just followed the instructions to create a WIX app.
But at when running npm run dev I get:

19:53:58 [wix] App Manifest updated. Refresh existing browser tabs to view the latest changes.
19:54:04 [ERROR] [vite] Internal server error: require is not defined
      at runInRunnerObject (workers/runner-worker/index.js:106:3)
      at _NonRunnablePipeline.getMiddleware (/home/will/Devel/External-Companies/yangteataiwan/line-payment-101/node_modules/.vite/deps_ssr/chunk-KISBL6D5.js?v=5595af8c:951:34)
      at _RenderContext.create (/home/will/Devel/External-Companies/yangteataiwan/line-payment-101/node_modules/.vite/deps_ssr/chunk-IAPQODBZ.js?v=5595af8c:1386:32)
      at DevApp.render (/home/will/Devel/External-Companies/yangteataiwan/line-payment-101/node_modules/.vite/deps_ssr/chunk-IAPQODBZ.js?v=5595af8c:2506:29)
      at Object.handle [as fetch] (/home/will/Devel/External-Companies/yangteataiwan/line-payment-101/node_modules/.vite/deps_ssr/[at]astrojs_cloudflare_entrypoints_server.js?v=e0e58621:211:20)
      at maybeCaptureError (workers/runner-worker/index.js:50:10)

Root Cause:
I was checking this issue with an IA and it seems to be this:

Astro 6’s Cloudflare adapter uses the workerd runtime, which only supports ESM.
However, the entire [at]wix/ ecosystem (including [at]wix/astro, [at]wix/essentials,
[at]wix/sdk, [at]wix/design-system, etc.) is compiled to CommonJS (cjs/ builds).

Steps to Reproduce:

  1. npm create wix-app[at]latest
  2. npm run dev
  3. Error appears immediately

Expected Behavior:
wix dev should work with Astro 6 + Cloudflare without require is not defined errors.

Actual Behavior:
Server crashes because workerd doesn’t support CommonJS require().

Workarounds Tried:

  • optimizeDeps.include — insufficient, too many CJS packages
  • ssr.noExternal — did not resolve

Maybe I could downgrading to Astro 5 to make it works but is not a long-term solution

Request:

  • Is it possible to migrate [at]wix/astro and its dependencies to ESM?
  • Otherwise is there an official workaround for Astro 6 + Cloudflare compatibility. ?

NOTE
I replaced the at symbol with “[at]” to be able to post this, because the wix forum consider it as a reference to a user and because is my first post I cannot reference other users.

Any help is highly appreciated.
Regards!

Do you also get this error in Build and Release Commands? Also have you built and released an app version before?

No, this is my first time on this.
I just was following videos in youtube and the official documentation to create an app in WIX, it is my first time with it.
And I just execute npm run dev for first time.

Thank you for your answer.
Regards!

Try running “npm run build” followed by “npm run release” commands first. The new CLI needs to release an app version first as well. See if you see the same error there.

The first execution npm run build was successfully.

$ npm run build

> line-payment-101@1.0.0 build
> wix build

10:30:22 [@astrojs/cloudflare] Enabling image processing with Cloudflare Images for production with the "IMAGES" Images binding.
10:30:22 [@astrojs/cloudflare] Enabling sessions with Cloudflare KV with the "SESSION" KV binding.
10:30:22 [vite] Re-optimizing dependencies because vite config has changed
10:30:22 [WARN] [vite] Failed to resolve dependency: fast-glob, present in ssr 'optimizeDeps.include'
Using secrets defined in .env.local
10:30:27 [vite] Re-optimizing dependencies because vite config has changed
10:30:27 [vite] Re-optimizing dependencies because vite config has changed
10:30:27 [WARN] [vite] Failed to resolve dependency: @wix/stores, present in client 'optimizeDeps.include'
10:30:27 [WARN] [vite] Failed to resolve dependency: fast-glob, present in astro 'optimizeDeps.include'
10:30:28 [types] Generated 5.62s
10:30:28 [build] output: "server"
10:30:28 [build] mode: "server"
10:30:28 [build] directory: /home/will/Devel/External-Companies/yangteataiwan/line-payment-101/dist/
10:30:28 [build] adapter: @astrojs/cloudflare
10:30:28 [build] Collecting build info...
10:30:28 [build] ✓ Completed in 5.69s.
10:30:28 [build] Building server entrypoints...
Using secrets defined in .env.local
10:30:29 [vite] ✓ built in 1.38s
Using secrets defined in .env.local
10:30:31 [vite] ✓ built in 1.59s
10:30:37 [vite] ✓ built in 6.14s
10:30:37 [build] Rearranging server assets...
10:30:37 [build] ✓ Completed in 9.17s.
10:30:37 [build] Server built in 14.87s
10:30:37 [build] Complete!

Then the second execution npm run release gave me an error:

$ npm run release

> line-payment-101@1.0.0 release
> wix release

(node:7965) TimeoutNaNWarning: NaN is not a number.
Timeout duration was set to 1.
(Use `node --trace-warnings ...` to show where the warning was created)
Before creating a new version, let's create a preview of your app

⠧ Uploading your application files...
✖ An error occoured while completing app deployment.

💡 This is probably a temporary system error and has been logged. Try again shortly.

Your experience matters to us. Would you like to submit feedback regarding this incident?
We may contact you by email in case we need more details.

? Submit feedback? (y/N)

And after that, when runningnpm run dev and then visit http://localhost:4321/ with the local server running, it still shows me this error:

18:15:44 [ERROR] [vite] Internal server error: require is not defined
      at runInRunnerObject (workers/runner-worker/index.js:106:3)
      at _NonRunnablePipeline.getMiddleware (/home/will/Devel/External-Companies/yangteataiwan/line-payment-101/node_modules/.vite/deps_ssr/chunk-KISBL6D5.js?v=05b469bc:951:34)
      at _RenderContext.create (/home/will/Devel/External-Companies/yangteataiwan/line-payment-101/node_modules/.vite/deps_ssr/chunk-IAPQODBZ.js?v=05b469bc:1386:32)
      at DevApp.render (/home/will/Devel/External-Companies/yangteataiwan/line-payment-101/node_modules/.vite/deps_ssr/chunk-IAPQODBZ.js?v=05b469bc:2506:29)
      at Object.handle [as fetch] (/home/will/Devel/External-Companies/yangteataiwan/line-payment-101/node_modules/.vite/deps_ssr/@astrojs_cloudflare_entrypoints_server.js?v=05b469bc:211:20)
      at maybeCaptureError (workers/runner-worker/index.js:50:10)

Backup the Entire Project File Somewhere and Make a Duplicate first… Then try following -

clear Vite’s dependency cache. Run

rm -rf node_modules/.vite

(If you are on Windows, you can just manually delete the .vite folder inside node_modules).

start your dev server with the --force flag to force Vite to re-optimize dependencies cleanly:

Run

npm run dev -- --force

After that, run the following -

npm update @wix/cli @wix/sdk

Hi!
I deleted .vite usando
npm run dev -- --force

The I ran
npm run dev -- --force

But that option doesn’t exists.
npm run dev -- --force

Then I ran
npm update @wix/cli @wix/sdk

And try again
npm run dev

But nothing changed, still have the same problem.
Then I try to create a new project from scratch just to check.

  1. Create new app with npm create @wix/@latest app
│
│ Create Wix App
│
? What would you like to do?
│
│ ✔ Create a new Wix app
│
? How would you like to create your new app?
│
│ ✔ Create a basic app
│
▶ Enter a name for your app
│
│ ✔ MyNewApp
│
▶ Enter a folder name for your project
│
│ ✔ my-new-app
│
? Would you like to configure Wix MCP for your IDE?
│
│ ✔ No (You always can do it later)
│
✔  Success  MyNewApp has been registered successfully.
│
▶ Enter a namespace for your app
│
│ ✔ my-new-app
│
▶ Enter a code identifier for your project
│
│ ✔ my_new_app
│
│
│ Generating your app...
│
│ ✔ [1/6] Project files generated!
│ ✔ [2/6] Local git repository initialized!
│ ✔ [3/6] Dependencies installed!
│ ✔ [4/6] Wix skills added!
│ ✔ [5/6] Agent configuration files generated!
│ ✔ [6/6] Changes committed!
│
👉 Results: ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                    │
│   You are ready to start developing MyNewApp!                                                                                                                                                                      │
│                                                                                                                                                                                                                    │
│   Next Steps:                                                                                                                                                                                                      │
│                                                                                                                                                                                                                    │
│   👟 Run the local development environment                                                                                                                                                                         │
│      cd my-new-app                                                                                                                                                                                                 │
│      npm run dev                                                                                                                                                                                                   │
│                                                                                                                                                                                                                    │
│   🎯 Extend your app                                                                                                                                                                                               │
│      npm run generate                                                                                                                                                                                              │
│                                                                                                                                                                                                                    │
│   🤝 View your App in the App Dashboard (https://dev.wix.com/apps/76d787f3-1685-4507-9081-6a4cb6c2d2dd/home)                                                                                                       │
│                                                                                                                                                                                                                    │
│   📚 For guides and API references visit our documentation (https://dev.wix.com/docs/build-apps/developer-tools/cli/get-started/about-the-wix-cli-for-apps)                                                        │
│                                                                                                                                                                                                                    │
│   💬 Join our Discord community (https://discord.gg/wixstudio)                                                                                                                                                     │
│                                                                                                                                                                                                                    │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

  1. run npm run dev in my project
[user@host my-new-app]$ npm run dev --verbose
npm verbose cli /home/USER/.nvm/versions/node/vX.X.X/bin/node /home/USER/.nvm/versions/node/vX.X.X/bin/npm
npm info using npm@X.X.X
npm info using node@vX.X.X
npm verbose title npm run dev
npm verbose argv "run" "dev" "--loglevel" "verbose"
npm verbose logfile logs-max:10 dir:/home/USER/.npm/_logs/ZZZZ-ZZ-ZZTZZ_ZZ_ZZ_ZZXZ-
npm verbose logfile /home/USER/.npm/_logs/ZZZZ-ZZ-ZZTZZ_ZZ_ZZ_ZZXZ-debug-0.log

> my-new-app@1.0.0 dev
> wix dev

npm verbose cli /home/USER/.nvm/versions/node/vX.X.X/bin/node /home/USER/.nvm/versions/node/vX.X.X/lib/node_modules/npm/bin/npm-cli.js
npm info using npm@X.X.X
npm info using node@vX.X.X
npm verbose title npm exec astro dev
npm verbose argv "exec" "--yes" "false" "--" "astro" "dev"
npm verbose logfile logs-max:10 dir:/home/USER/.npm/_logs/ZZZZ-ZZ-ZZTZZ_ZZ_ZZ_ZZXZ-
npm verbose logfile /home/USER/.npm/_logs/ZZZZ-ZZ-ZZTZZ_ZZ_ZZ_ZZXZ-debug-0.log
ZZ:ZZ:ZZ [@astrojs/cloudflare] Enabling sessions with Cloudflare KV with the "SESSION" KV binding.
ZZ:ZZ:ZZ [@astrojs/cloudflare] If you see the error "Invalid binding `SESSION`" in your build output, you need to add the binding to your wrangler config file.
Using vars defined in .env.local
ZZ:ZZ:ZZ [types] Generated 0ms
ZZ:ZZ:ZZ [content] Syncing content
ZZ:ZZ:ZZ [content] Synced content

 astro  v5.18.1 ready in 1054 ms

┃ Local    http://localhost:4321/
┃ Network  use --host to expose

ZZ:ZZ:ZZ watching for file changes...
ZZ:ZZ:ZZ [wix] App Manifest updated. Refresh existing browser tabs to view the latest changes.
ZZ:ZZ:ZZ [ERROR] Failed to fetch tokens from OAuth API: Bad Request. request id: REDACTED. Response: {"error":"unknown_error"}
  Stack trace:
    at /home/USER/.../my-new-app/node_modules/@wix/sdk/build/auth/oauth2/OAuthStrategy.js:416:15
    [...] See full stack trace in the browser, or rerun with --verbose.
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Current Dev Site: REDACTED (Press  C ░ to switch)

Open the preview on:
  › Site (https://dev.wix.com/wix-cli-redirect-service/redirect?platform=site&versionOverrideId=REDACTED&tenantId=REDACTED&appId=REDACTED)
  › Editor (https://dev.wix.com/wix-cli-redirect-service/redirect?platform=editor&versionOverrideId=REDACTED&tenantId=REDACTED&appId=REDACTED)
  › Dashboard (https://dev.wix.com/wix-cli-redirect-service/redirect?platform=dashboard&versionOverrideId=REDACTED&tenantId=REDACTED&appId=REDACTED)

This time I could successfully able to get into the Site, Editor and Dashboard sites.
But, when I try to open http://localhost:4321/ I get

ZZ:ZZ:ZZ [ERROR] Failed to fetch tokens from OAuth API: Bad Request. request id: REDACTED. Response: {"error":"unknown_error"}
  Stack trace:
    at /home/USER/.../my-new-app/node_modules/@wix/sdk/build/auth/oauth2/OAuthStrategy.js:416:15
    [...] See full stack trace in the browser, or rerun with --verbose.

Then:

  1. Does this confirm that in the previous project, the problem is the libraries in cache?
  2. For this new issue I should I open a new topic or continue here?

Thank you so much for your answers!
Regards!

When you navigate directly to http://localhost:4321/, none of that Wix-specific context exists. The SDK fires off an authentication request to the Wix API without the required state or instance parameters, resulting in the 400 Bad Request: {"error":"unknown_error"} from the OAuth API.

After you build the App Widgets or Extensions, release a version that will register your extensions(it is required in new CLI, Legecy CLI can show widgets without the release).

So First Run

 npm run build

Then

npm run release

Follow the process of releasing the app as given in the terminal

Then run the npm run build and finally npm run preview, that should give you the right preview URL. If its a new app, it will ask you to install the app in a Wix website first.