Skip to content

Commit 587de6e

Browse files
Add bundling issues section in Wrangler module aliasing documentation (#29050)
1 parent fce28ea commit 587de6e

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/content/docs/workers/wrangler/configuration.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,18 @@ import { bar } from "foo";
15311531
console.log(bar); // returns "baz"
15321532
```
15331533

1534+
### Bundling issues
1535+
1536+
When Wrangler bundles your Worker, it might fail to resolve dependencies. Setting up an alias for such dependencies is a simple way to fix the issue.
1537+
1538+
However, before doing so, verify that the package is correctly installed in your project, either as a direct dependency in `package.json` or as a transitive dependency.
1539+
1540+
If an alias is the correct solution for your dependency issue, you have several options:
1541+
1542+
- **Alternative implementation** — Implement the module's logic in a Worker-compatible manner, ensuring that all the functionality remains intact.
1543+
- **No-op module** — If the module's logic is unused or irrelevant, point the alias to an empty file. This makes the module a no-op while fixing the bundling issue.
1544+
- **Runtime error** — If the module's logic is unused and the Worker should not attempt to use it (for example, because of security vulnerabilities), point the alias to a file with a single top-level `throw` statement. This fixes the bundling issue while ensuring the module is never actually used.
1545+
15341546
### Example: Aliasing dependencies from NPM
15351547

15361548
You can use module aliasing to provide an implementation of an NPM package that does not work on Workers — even if you only rely on that NPM package indirectly, as a dependency of one of your Worker's dependencies.

0 commit comments

Comments
 (0)