windicss / vite-plugin-windicss

🍃 Windi CSS for Vite ⚡️
MIT License
852 stars 65 forks source link

Pug extractor not working with type="module" in package.json #272

Open davay42 opened 2 years ago

davay42 commented 2 years ago

Describe the bug I've been struggling with windicss not producing styles for my lang="pug" Vue SFCs in my components library. Manually adding the WindiCSS({ extract: [PugExtractor], }), didn't help. But then I looked through the extractor code and saw the dynamic require of pug. This lead me to try to remove "type="module" line in my package.json and all the styles got generated just fine.

Actual repo https://github.com/DeFUCC/gun-vue/tree/master/components

Versions

Additonal Context

theozhang32 commented 1 year ago

Seems like https://github.com/windicss/vite-plugin-windicss/issues/266#issue-1083126344

theozhang32 commented 1 year ago

I tried these

  1. use import { createRequire } from 'node:module'
  2. replace require.resolve('pug') to createRequire(import.meta.url).resolve('pug') https://github.com/windicss/vite-plugin-windicss/blob/d5ad27b6e8252dd6aad00b1e0630d8530b60dd85/packages/plugin-utils/src/extractors/helper.ts#L18
  3. replace require('pug') to createRequire(import.meta.url)('pug') https://github.com/windicss/vite-plugin-windicss/blob/d5ad27b6e8252dd6aad00b1e0630d8530b60dd85/packages/plugin-utils/src/extractors/pug.ts#L8

Reference from https://stackoverflow.com/questions/59443525/require-not-working-in-module-type-nodejs-script