javascriptviteserver-side-renderingrollup

Vite/Rollup: No name was provided for external module/Failed to resolve module specifier


For some reason, Rollup refuses to recognize my global external dependencies.

From my vite.config.ts:

export default defineConfig({
  build: {
    rollupOptions: {
      external: ['radash', '@leeoniya/ufuzzy'],
      output: {
        globals: {
          radash: '_',
          '@leeoniya/ufuzzy': 'Fuzzy',
        },
      },
    },
  },
[...]

From my Vite build:

No name was provided for external module "radash" in "output.globals" – guessing "_".
No name was provided for external module "@leeoniya/ufuzzy" in "output.globals" – guessing "Fuzzy".
No name was provided for external module "radash" in "output.globals" – guessing "_".
No name was provided for external module "@leeoniya/ufuzzy" in "output.globals" – guessing "Fuzzy".
No name was provided for external module "radash" in "output.globals" – guessing "_".
No name was provided for external module "@leeoniya/ufuzzy" in "output.globals" – guessing "Fuzzy".
No name was provided for external module "radash" in "output.globals" – guessing "_".
No name was provided for external module "@leeoniya/ufuzzy" in "output.globals" – guessing "Fuzzy".
No name was provided for external module "radash" in "output.globals" – guessing "_".
No name was provided for external module "@leeoniya/ufuzzy" in "output.globals" – guessing "Fuzzy".
No name was provided for external module "radash" in "output.globals" – guessing "_".
No name was provided for external module "@leeoniya/ufuzzy" in "output.globals" – guessing "Fuzzy".

I've also tried using vite-plugin-externals with the same result. The consequences is that my builds, which finish successfully, are broken when loaded in the browser and throw a console error:

Failed to resolve module specifier "radash". Relative references must start with either "/", "./", or "../".

Is this a bug or am I doing something wrong? I'm using Sveltekit if that matters.


Solution

  • The two issues, the first being the warnings about unnamed modules, and the second about not being able to 'resolve module specifier' are actually not really related though they appear to be as they both deal with the same imports.

    The issue was that these are Web Workers I was importing using the ?worker method and not the import.meta.url method. As such, I was improperly importing dependencies for those workers from my local project thinking incorrectly that they'd be imported.

    Instead, I had to build my workers using a separate TypeScript config so that they compiled to the static folder, use unpkg.com with a standard import call (not importScripts) for my workers' dependencies, and in my components, use the import.meta.url method rather than import worker from '/workers/worker.js?worker'.