Skip to content

Uncaught TypeError: Failed to construct 'URL': Invalid URL (vite 3) #9543

@caoxiemeihao

Description

@caoxiemeihao

This Issue re-open form #9180
Related Issue electron-vite/electron-vite-vue#212

Describe the bug

I tried to Debug to find out the BUG, and finally I found that the BUG is caused by esbuild

👉 esbuild#2441 🐞 import.meta.url transpile.

But this BUG only appears when I use base: './' and format: 'cjs'. The following options are often used with Electron-Renderer

export {
  base: './', // Here
  build: {
    minify: false,
    rollupOptions: {
      output: {
        format: 'cjs', // Here
      },
    },
  },
}

Reproduction

https://stackblitz.com/edit/vite-invalid-url?file=vite.config.js

System Info

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
    Memory: 1010.00 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 16.13.0 - /usr/local/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.1.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 103.0.5060.134
    Safari: 15.4
  npmPackages:
    vite: ^3.0.4 => 3.0.4

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions