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

[unocss:global:build:generate] [unocss] does not found CSS placeholder in the generated chunks #1341

Closed
ckvv opened this issue Jul 26, 2022 · 10 comments · Fixed by #1400
Closed
Labels
bug Something isn't working upstream vite

Comments

@ckvv
Copy link
Contributor

ckvv commented Jul 26, 2022

https://github.com/ckvv/vite-project

The following error is thrown when the output file is multiple in library mode
https://github.com/ckvv/vite-project/blob/3b4f3c84c2b9cd4f0e0ee883da6439077cad1811/vite.config.js#L12

[unocss:global:build:generate] [unocss] does not found CSS placeholder in the generated chunks,
this is likely an internal bug of unocss vite plugin
error during build:
Error: [unocss] does not found CSS placeholder in the generated chunks,
this is likely an internal bug of unocss vite plugin
    at Object.generateBundle (/Users/chenkai/Downloads/mini-vue/node_modules/.pnpm/@unocss+vite@0.44.7_vite@2.9.14/node_modules/@unocss/vite/dist/index.cjs:364:22)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Bundle.generate (/Users/chenkai/Downloads/mini-vue/node_modules/.pnpm/rollup@2.77.1/node_modules/rollup/dist/shared/rollup.js:16103:9)
    at async /Users/chenkai/Downloads/mini-vue/node_modules/.pnpm/rollup@2.77.1/node_modules/rollup/dist/shared/rollup.js:23746:27
    at async catchUnfinishedHookActions (/Users/chenkai/Downloads/mini-vue/node_modules/.pnpm/rollup@2.77.1/node_modules/rollup/dist/shared/rollup.js:23161:20)
    at async doBuild (/Users/chenkai/Downloads/mini-vue/node_modules/.pnpm/vite@2.9.14/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:41721:26)
    at async build (/Users/chenkai/Downloads/mini-vue/node_modules/.pnpm/vite@2.9.14/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:41552:16)
    at async CAC.<anonymous> (/Users/chenkai/Downloads/mini-vue/node_modules/.pnpm/vite@2.9.14/node_modules/vite/dist/node/cli.js:738:9)

The problem occurs in version v0.43.2

related to this commit#1217

@Xwudao
Copy link

Xwudao commented Jul 26, 2022

With lib mode in vite.js, the option build.cssCodeSplit force be set to false https://vitejs.dev/config/build-options.html#build-csscodesplit

And, build.cssCodeSplit=false, the unocss will occur this error.

That is to say, you can manual set it to true, may resolve your problem.

@kingcw
Copy link

kingcw commented Jul 27, 2022

These steps worked for me, it's for mode "global", but you can play with other modes to seek the correct config:

  1. in package.json, needs to add "type" field:
"type": "module"
  1. set build.cssCodeSplit=false
  2. if you want to generate "umd" or "iife", you can't specify filenames, so in vite.config.ts:
   build: {
        lib: {
            entry: resolve(__dirname, "index.ts"),
            name: "xxx",
        },
        rollupOptions: {
            output: [
                    ...
                    {
                           dir: "dist/umd",
                           format: "umd",
                           name: "xxx",
                           sourcemap: false,
                     }
                    ...
            ]
        }
   }

but you can specify entryFilenames for es and cjs

this should also be the answer to issue #1241 and #1332

Unocss: v0.44.7
Vite: 3.0.3

@kingcw
Copy link

kingcw commented Jul 27, 2022

above config only works for umd.

For iife, after set build.cssCodeSplit = true, it's a hit and miss, you build several times, it might succeed one time. The inconsistency looks like a parallel async bug.

but just use umd for now would be fine I guess.

@alvarosabu
Copy link

@Xwudao you might want to be able to export the styles in your library to be imported separately by the consume in lib mode.

@alvarosabu
Copy link

@ckvv it must be something recent because I fixed it by downgrading to "unocss": "^0.33.4"

@Jelenkee
Copy link

Jelenkee commented Aug 3, 2022

I'm having the same problem with Astro. In dev mode everything works fine but when I build the project, it fails.
Setting build.cssCodeSplit to false did not help.
I'm using unocss 0.45.1

astro.config.mjs

import { defineConfig } from 'astro/config';
import { presetUno } from "unocss";
import unocss from "unocss/vite";
import icons from "@unocss/preset-icons";
import svelte from "@astrojs/svelte";
import { extractorSvelte } from "@unocss/core";


export default defineConfig({
    integrations: [svelte()],
    vite: {
        plugins: [
            unocss({
                presets: [
                    presetUno(),
                    icons()
                ],
                extractors: [extractorSvelte],
            }),
        ],
        ssr: {
            noExternal: ["modern-normalize"]
        }
    }
});

layout.astro

---
import "modern-normalize";
import "uno.css";
import "../main.scss"
import Header from "../layouts/header.astro";
---
<some-markup>

@Xwudao
Copy link

Xwudao commented Aug 4, 2022

Setting build.cssCodeSplit to false did not help.

we said set it to true

@antfu
Copy link
Member

antfu commented Aug 4, 2022

This is probable related to https://github.com/vitejs/vite/discussions/9443

@antfu antfu added bug Something isn't working upstream vite labels Aug 4, 2022
@Jelenkee
Copy link

Jelenkee commented Aug 4, 2022

Setting build.cssCodeSplit to false did not help.

we said set it to true

Did not help either. According to vite docs true is the default

@vipero07
Copy link
Contributor

vipero07 commented Aug 9, 2022

Setting build.cssCodeSplit to false did not help.

we said set it to true

This actually fixed the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream vite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants