#Using NPM packages in Workers

5 messages · Page 1 of 1 (latest)

willow silo
#

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!

still field
#

Just npm i package and then import { foo } from "package" as you'd expect

willow silo
#

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?

#
 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"