Next.js Discord

Discord Forum

Why using a URL constructor with a file path to an esm file throws an error?

Unanswered
Polar bear posted this in #help-forum
Open in Discord
Polar bearOP
Why using a URL constructor with a file path to an esm file throws an error?

pdfjs.GlobalWorkerOptions.workerSrc = new URL(
  "pdfjs-dist/build/pdf.worker.min.mjs",
  import.meta.url
).toString();

I get how to fix this error. Updating my nextjs config by setting esmExternals to loose fixes it. I am just curious why nextjs doesn't allow me to construct a url with an esm file path. Is nextjs misunderstanding this to be an import?

0 Replies