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

cssCodeSplit with multiple entry points emits bogus sourcemap files #14047

Closed
7 tasks done
silverwind opened this issue Aug 8, 2023 · 2 comments · Fixed by #14290
Closed
7 tasks done

cssCodeSplit with multiple entry points emits bogus sourcemap files #14047

silverwind opened this issue Aug 8, 2023 · 2 comments · Fixed by #14290

Comments

@silverwind
Copy link

silverwind commented Aug 8, 2023

Describe the bug

When cssCodeSplit is enabled and multiple entry points with the same name but different file extension are present, vite generates invalid sourcemap files which refer nonexistant files and serve no purpose.

Reproduction

https://github.com/silverwind/vite-empty-sourcemap

export default defineConfig({
  build: {
    cssCodeSplit: true,
    sourcemap: true,
    lib: {
      entry: [
        "./index.js",
        "./index.css",
      ],
      formats: ["es"],
    },
  },
});

Steps to reproduce

git clone https://github.com/silverwind/vite-empty-sourcemap
cd vite-empty-sourcemap
npm install
npx vite build
ls -la dist

Expected

index.css
index.js
index.js.map

Actual

index.css
index.js
index.js.map
index2.js.map  <-- Bogus sourcemap file

The sourcemap refers to a nonexistant file index2.js:

cat dist/index2.js.map
{"version":3,"file":"index2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}

System Info

System:
    OS: macOS 13.5
    CPU: (8) x64 Intel(R) Core(TM) i7-1060NG7 CPU @ 1.20GHz
    Memory: 141.58 MB / 16.00 GB
    Shell: 5.9 - /usr/local/bin/zsh
  Binaries:
    Node: 20.5.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.8.1 - ~/.npm-global/bin/npm
    pnpm: 8.6.11 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 114.0.5735.133
    Safari: 16.6
  npmPackages:
    vite: 4.4.9 => 4.4.9

Used Package Manager

npm

Logs

Click to expand!
vite v4.4.9 building for production...
✓ 2 modules transformed.
dist/index.css  0.01 kB │ gzip: 0.03 kB
dist/index.js   0.09 kB │ gzip: 0.11 kB │ map: 0.16 kB
✓ built in 88ms

Validations

@silverwind silverwind changed the title cssCodeSplit with multiple entry points results in empty sourcemap files cssCodeSplit with multiple entry points results in bogus sourcemap files Aug 8, 2023
@silverwind silverwind changed the title cssCodeSplit with multiple entry points results in bogus sourcemap files cssCodeSplit with multiple entry points emits bogus sourcemap files Aug 8, 2023
@kinfuy
Copy link
Contributor

kinfuy commented Aug 9, 2023

It seems that it was caused by adding CSS files to the entry. I'm not sure if this is the expected behavior

@silverwind
Copy link
Author

Yes, the CSS in entry this is intentional. I'm adding it there because I require the library consumer to explicity @import it in their CSS. I don't want to import CSS inside JS because that makes node unable to import the file (vitest-dev/vitest#3862 is related). FYI, this is how it looks in my package.json:

  "exports": {
    "./dist/*.css": {
      "import": "./dist/*.css"
    }
  }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants