🐛 BUG: Wrangler fails to compile worker when using modules that are compatible with workers (via NPM)
See original GitHub issueWhat version of Wrangler
are you using?
0.0.21
What operating system are you using?
Linux
Describe the Bug
Hi,
When creating a project via wrangler init (either with or without typescript)
You are unable to import any module from npm that is compatible with workers.
Examples tried were itty-router which is compatible with cloudflare workers and the module syntax and Cloudflare’s own @cloudflare/kv-asset-handler
Both of which provide this error when running via wrangler dev, wrangler dev --local or wrangler publish
✘ [ERROR] [plugin wrangler-module-collector] ENOENT: no such file or directory, open '/workspaces/api/src/itty-router
src/index.ts:1:23:
1 │ import { Router } from "itty-router";
╵ ~~~~~~~~~~~~~
This error came from the "onResolve" callback registered here:
../../usr/local/share/npm-global/lib/node_modules/wrangler/wrangler-dist/cli.js:138097:15:
138097 │ build5.onResolve({
╵ ~~~~~~~~~
at setup (/usr/local/share/npm-global/lib/node_modules/wrangler/wrangler-dist/cli.js:138097:16)
at handlePlugins (/usr/local/share/npm-global/lib/node_modules/wrangler/node_modules/esbuild/lib/main.js:842:23)
at Object.buildOrServe (/usr/local/share/npm-global/lib/node_modules/wrangler/node_modules/esbuild/lib/main.js:1136:7)
at /usr/local/share/npm-global/lib/node_modules/wrangler/node_modules/esbuild/lib/main.js:2064:17
at new Promise (<anonymous>)
at Object.build (/usr/local/share/npm-global/lib/node_modules/wrangler/node_modules/esbuild/lib/main.js:2063:14)
at Object.build (/usr/local/share/npm-global/lib/node_modules/wrangler/node_modules/esbuild/lib/main.js:1913:51)
at bundleWorker (/usr/local/share/npm-global/lib/node_modules/wrangler/wrangler-dist/cli.js:138880:33)
at build5 (/usr/local/share/npm-global/lib/node_modules/wrangler/wrangler-dist/cli.js:138958:75)`
It appears so though no consideration is taken for external modules or “libraries” and instead everything is assumed to be a local module accessible via ./ ?
Wrangler 1 as expected works via webpack to resolve these modules, and from what I understand Wrangler 2 is using esbuild to do the same, so I am struggling work out what is wrong that is causing even this basic code to fail. Does wrangler 2 not currently support any modules that are not ./ accessible?
This should really be supported if they aren’t there is a lot of useful frameworks or libraries that the community has created that can be used on Cloudflare workers (https://workers.cloudflare.com/works) - its a shame if wrangler 2 is going backwards in this department to not support them anymore.
Any insight into this issue would be great.
Thanks 👍
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
This is extremely weird, looks like a bug. I’ll investigate this as soon as I can.
This should be fixed in 0.0.22. Lemme know if you face any further problems, thanks!