Using NPM packages in Workers
# workers-help
t
My understanding is that Wrangler will use esbuild to bundle any NPM packages upon deploy. I was trying to use just one package (probe-image-size) and can't get this to happen. I was developing locally and got errors then I tried the command to do a dry run locally and when I did so it still didn't bundle it... Is it possible to use NPM packages? What am I missing? Thank you!
k
Just
npm i package
and then
import { foo } from "package"
as you'd expect
t
Hmmm. Well I'm happy to hear it's that simple however I did that already
I did that at the root level, should I
npm i
in the src subfolder?
Copy code
src/index.js:1:20:
      1 │ let probe = require("probe-image-size");
        ╵                     ~~~~~~~~~~~~~~~~~~

  The Yarn Plug'n'Play manifest forbids importing "probe-image-size" here because it's not listed as a dependency of this package:

    ../../../.pnp.js:47:33:
      47 │           "packageDependencies": [
         ╵                                  ^

  You can mark the path "probe-image-size" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.


✘ [ERROR] Build failed with 1 error:

  src/index.js:1:20: ERROR: Could not resolve "probe-image-size"
Based on this error, could it be yarn related? I'm not using yarn. I googled and didn't see much of anything that could be related
4 Views