opennextjs / opennextjs-cloudflare

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

Successful Build But Cannot Start #74

Closed justindjeumenet closed 1 month ago

justindjeumenet commented 1 month ago

Hey guys!

next.js version: 14.2.5 wrangler version: 3.80.0

I was able to build successfully but the application cannot start and here is the error:

inlineEvalManifest

patchCached

Worker saved in /Users/justindjeumene/WebstormProjects/cloudflare-invoices-center/.worker-next/index.mjs 🚀

⛅️ wrangler 3.80.0 (update available 3.80.1)

Your worker has access to the following bindings:

✘ [ERROR] Could not resolve "yoga-layout"

.worker-next/.next/standalone/node_modules/@react-pdf/layout/lib/index.cjs:10:19:
  10 │ var Yoga = require('yoga-layout');
     ╵                    ~~~~~~~~~~~~~

The module "./src/entrypoint/wasm-async-web.js" was not found on the file system:

.worker-next/.next/standalone/node_modules/yoga-layout/package.json:14:17:
  14 │       "browser": "./src/entrypoint/wasm-async-web.js",
     ╵                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can mark the path "yoga-layout" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.

✘ [ERROR] Could not resolve "fontkit"

.worker-next/.next/standalone/node_modules/@react-pdf/pdfkit/lib/pdfkit.cjs:8:22:
  8 │ var fontkit = require('fontkit');
    ╵                       ~~~~~~~~~

The module "./dist/browser.cjs" was not found on the file system:

.worker-next/.next/standalone/node_modules/fontkit/package.json:37:15:
  37 │     "require": "./dist/browser.cjs"
     ╵                ~~~~~~~~~~~~~~~~~~~~

You can mark the path "fontkit" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.

✘ [ERROR] Could not resolve "uuid"

.worker-next/.next/standalone/node_modules/@smithy/middleware-retry/dist-cjs/index.js:51:26:
  51 │ var import_uuid = require("uuid");
     ╵                           ~~~~~~

The module "./dist/commonjs-browser/index.js" was not found on the file system:

.worker-next/.next/standalone/node_modules/uuid/package.json:34:19:
  34 │         "require": "./dist/commonjs-browser/index.js"
     ╵                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Failed to build

╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ │ [b] open a browser, [d] open devtools, [l] turn off local mode, [c] clear console, [x] to exit │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ? Would you like to report this error to Cloudflare? › (Y/n)

Any idea guys? I tried to fix it myself but need to dig in your code to understand this situation. Thanks Justin

justindjeumenet commented 1 month ago

The same build is successful with the command "next build" and starts successfully but NOT with : "deploy": "cloudflare && wrangler deploy", "preview": "cloudflare && wrangler dev",

imumesh18 commented 1 month ago

Hey @justindjeumenet check this out. https://opennext.js.org/cloudflare/troubleshooting#my-app-fails-to-build-when-i-import-a-specific-npm-package

TLDR: Set the below envs when building and starting your server.

WRANGLER_BUILD_CONDITIONS=""
WRANGLER_BUILD_PLATFORM="node"
justindjeumenet commented 1 month ago

omg!! @imumesh18 you saved me. Thank you. It works fine. I am going to close this issue.