File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 44 "dev-deploy" : " Develop and Deploy" ,
55 "env-vars" : " Environment Variables" ,
66 "image" : " Image Optimization" ,
7- "custom-worker" : " Custom Worker"
7+ "custom-worker" : " Custom Worker" ,
8+ "keep_names" : " __name issues"
89}
Original file line number Diff line number Diff line change 1+ import { Callout } from " nextra/components" ;
2+
3+ ## ` __name ` issues
4+
5+ When using the OpenNext adapter, Wrangler processes the worker's code with [ esbuild] ( https://esbuild.github.io/ ) , and by default
6+ enables the [ ` keep-names ` ] ( https://esbuild.github.io/api/#keep-names ) option. While this is generally useful for debugging, it can
7+ cause issues with certain Next.js libraries (e.g. [ next-themes] ( https://github.com/pacocoursey/next-themes ) ) that convert scripts
8+ to strings. This happens because ` esbuild ` introduces an ` __name ` function at the top of modules, which may inadvertently appear
9+ in the generated script strings. When these strings are evaluated at runtime, the ` __name ` function might therefore not be defined,
10+ leading to errors like the following:
11+ ```
12+ Uncaught ReferenceError: __name is not defined
13+ ```
14+
15+ <Callout >
16+ Note that depending on your minification settings, the ` __name ` identifier might be minified, making the error message
17+ less clear and potentially not explicitly mentioning ` __name ` in such cases.
18+ </Callout >
19+
20+ ### How to fix such issues
21+
22+ To fix the issue you can simply set the ` keep_names ` option to ` false ` in your ` wrangler.jsonc ` file, like in the following example:
23+
24+ ``` jsonc
25+ {
26+ " $schema" : " node_modules/wrangler/config-schema.json" ,
27+ " main" : " .open-next/worker.js" ,
28+ " name" : " my-app" ,
29+ " keep_names" : false ,
30+ /* ... */
31+ }
32+ ```
33+
34+ One potential drawback of this solution is that, depending on your minification settings, you may lose the ability to view the original
35+ function names in debugging tools.
36+
37+ <Callout >
38+ You must use Wrangler version ` 4.13.0 ` or later to use this option.
39+ </Callout >
You can’t perform that action at this time.
0 commit comments