Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error resolving package in node_module #401

Open
5 tasks done
davidnormo opened this issue Jan 31, 2025 · 0 comments
Open
5 tasks done

Error resolving package in node_module #401

davidnormo opened this issue Jan 31, 2025 · 0 comments

Comments

@davidnormo
Copy link

Describe the bug

I was attempting to read the pdf.js pdf.worker.mjs file as a raw string to base64 encode and start a worker. My import statement looked like this:

import pdfWorkerSrc from 'pdfjs-dist/build/pdf.worker.mjs?raw';

However esbuild failed with this error:

ENOENT: no such file or directory, open '[REDACTED]/customReport/src/pdfjs-dist/build/pdf.worker.mjs' [plugin raw]

    src/Widget.tsx:8:25:
      8 │ ...kerSrc from 'pdfjs-dist/build/pdf.worker.mjs?raw';
        ╵                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  This error came from the "onLoad" callback registered here:

    ../../node_modules/esbuild-plugin-raw/dist/index.js:52:12:
      52 │       build.onLoad({ filter: /\?raw$/, namespace:...
         ╵             ~~~~~~

What I think is going on is the onResolve handler in this plugin is interpreting pdfjs-dist/build/pdf.worker.mjs?raw as a relative module import rather than an absolute one from node_modules.

I've amended the plugin locally to get it to work but would like to hear your thoughts? Happy to open a PR if helpful

Reproduction

See description

System Info

System:
    OS: macOS 14.7.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 4.18 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.local/state/fnm_multishells/1973_1737969326022/bin/node
    Yarn: 1.22.22 - ~/.local/state/fnm_multishells/1973_1737969326022/bin/yarn
    npm: 10.8.3 - ~/dev/lens-app/node_modules/.bin/npm
    Watchman: 2024.11.11.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 131.0.6778.205
    Safari: 18.1

Used Package Manager

npm

Validations

  • Follow the Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A please open a GitHub Discussion.
  • The provided reproduction is a minimal reproducible example of the bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant