Skip to content

Resolution error on missing optional peerDependency #17

@marvinhagemeister

Description

@marvinhagemeister

The npm package ws has an optional peerDependency on bufferutil. In their code they check for this via:

if (!process.env.WS_NO_BUFFER_UTIL) {
  try {
    const bufferUtil = require('bufferutil');
   // ...
  } catch (e) {
    // Continue regardless of the error.
  }
}

But since the @deno/loader tries to initialize all packages up front it will error out.

Steps to reproduce

  1. Clone https://github.com/marvinhagemeister/deno-loader-optional-bug
  2. Run deno install
  3. Run deno run -A main.ts

Output:

$ deno run -A main.ts
error: Uncaught (in promise) Error: Could not find package 'bufferutil' from referrer 'file:///Users/marvinhagemeister/Library/Caches/deno/npm/registry.npmjs.org/ws/8.18.3/node_modules/ws/lib/buffer-util.js' (ws@8.18.3).
  const ret = new Error(getStringFromWasm0(arg0, arg1));
              ^
    at __wbindgen_error_new (https://jsr.io/@deno/loader/0.1.3/src/lib/rs_lib.internal.js:978:15)
    at <anonymous> (wasm://wasm/013c5e56:1:4115117)
    at <anonymous> (wasm://wasm/013c5e56:1:3914089)
    at <anonymous> (wasm://wasm/013c5e56:1:3978417)
    at DenoLoader.resolve (https://jsr.io/@deno/loader/0.1.3/src/lib/rs_lib.internal.js:318:24)
    at Loader.resolve (https://jsr.io/@deno/loader/0.1.3/src/mod.ts:194:31)
    at file:///Users/marvinhagemeister/dev/test/deno-loader-optional/main.ts:14:31

Original reported at denoland/fresh#3078

Metadata

Metadata

Assignees

No one assigned

    Labels

    important for freshIssues that are important for Fresh users

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions