-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b30aec3
commit 4abab8f
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
``` |