Skip to content

Commit

Permalink
Add troubleshooting page
Browse files Browse the repository at this point in the history
  • Loading branch information
irvinebroque committed Sep 26, 2024
1 parent b30aec3 commit 4abab8f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pages/cloudflare/troubleshooting.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { SITE } from '../../config';
import { Callout } from 'nextra/components';

## Troubleshooting

### My app fails to build when I import a specific NPM package

First, make sure that the `nodejs_compat` compatibility flag is enabled, and your compatibility date is set to on or after "2024-09-23", in your `wrangler.toml` file. [Refer to the Workers docs](https://developers.cloudflare.com/workers/runtime-apis/nodejs/) for more details on Node.js support in Cloudflare Workers.

Some NPM packages define multiple exports. For example:

```
"exports": {
"other": "./src/other.js",
"node": "./src/node.js",
"browser": "./src/browser.js",
"default": "./src/default.js"
},
```

When you use `@opennextjs/cloudflare`, [Wrangler](https://developers.cloudflare.com/workers/wrangler/) bundles your code before running it locally, or deploying it to Cloudflare. Wrangler has to choose which export to use, when you import a module. By default, Wrangler, which uses [esbuild](https://esbuild.github.io/), handles this in a way that is not compatible with some NPM packages.

You may want to modify how Wrangler resolves multiple exports, such that when you import packages, the `node` export, if present, is used. You can do do by defining the following variables in a `.env` file within the root directory of your Next.js app:

```
WRANGLER_BUILD_CONDITIONS=""
WRANGLER_BUILD_PLATFORM="node"
```

0 comments on commit 4abab8f

Please sign in to comment.