#No name was provided for external module/Failed to resolve module specifier

3 messages · Page 1 of 1 (latest)

old geode
#

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 are broken 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.

GitHub

use to external resources. Contribute to crcong/vite-plugin-externals development by creating an account on GitHub.

#

No name was provided for external module: Rollup won't recognize specified globals

old geode
#

Ok, I figured it out.

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. The fix was:

  1. To build my workers using a separate TypeScript config so that they compiled to the static folder.
  2. Use unpkg.com with a standard import call (not importScripts) for my workers' dependencies
  3. In my components, use the import.meta.url method like so:
  const workerUrl = new URL('/workers/inventorySearch.js', import.meta.url).href;
  worker = new Worker(workerUrl, { type: 'module' });