question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🐛 BUG: Wrangler fails to compile worker when using modules that are compatible with workers (via NPM)

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
threepointonecommented, Mar 21, 2022

This is extremely weird, looks like a bug. I’ll investigate this as soon as I can.

0reactions
threepointonecommented, Mar 21, 2022

This should be fixed in 0.0.22. Lemme know if you face any further problems, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack target=webworker prevents using some npm ...
run the worker ( wrangler preview ); it fails due to window not accessible. What did you expect to see? The worker should...
Read more >
Bundling · Cloudflare Workers docs
Bundling your Worker code takes multiple modules and bundles them into one. Sometimes, you might have modules that should not be inlined ...
Read more >
Fix Cloudflare Remix HMR Bug with patch-package - Justin Noel
First, fix the problem in the wrangler distribution at node_modules/wrangler/wrangler-dist/cli.js . Replace line 124103: buildWatchPaths: [ ...
Read more >
528360 – Combination of Junit 4, Java 9 modules, Maven and ...
I created a simple Java 9 / Maven project with a Main class and a JUnit 4 test class using the default Maven...
Read more >
worker - crates.io: Rust Package Registry
Use any local or remote crates and modules (as long as they compile to the wasm32-unknown-unknown target). Once you're ready to run your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found