Skip to content

fix: applying plugin on an empty css file #58

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

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

AloisSeckar
Copy link
Contributor

Yesterday, I am trying to add @nuxt/fonts module into my project where I already integrated Open Props using postcss-jit-props plugin. It turned out the plugin cannot handle empty css file (.nuxt/nuxt-fonts-global.css) that is auto-generated by @nuxt/fonts module and is empty when you don't specify any global font-family (which is common use case - fonts can be injected into CSS locally only where you need them).

The error was:

ERROR  Internal server error: [postcss] Cannot read properties of undefined (reading 'source')                                                   22:25:52  
  Plugin: vite:css
  File: C:/Programming/Git/nuxt-ignis/.nuxt/nuxt-fonts-global.css:undefined:NaN
      at Object.Once (C:\Programming\Git\nuxt-ignis\node_modules\.pnpm\postcss-jit-props@1.0.15_postcss@8.4.49\node_modules\postcss-jit-props\index.js:130:88)
      at LazyResult.runOnRoot (C:\Programming\Git\nuxt-ignis\node_modules\.pnpm\postcss@8.5.1\node_modules\postcss\lib\lazy-result.js:327:23)
      at LazyResult.runAsync (C:\Programming\Git\nuxt-ignis\node_modules\.pnpm\postcss@8.5.1\node_modules\postcss\lib\lazy-result.js:258:26)
      at LazyResult.async (C:\Programming\Git\nuxt-ignis\node_modules\.pnpm\postcss@8.5.1\node_modules\postcss\lib\lazy-result.js:160:30)
      at LazyResult.then (C:\Programming\Git\nuxt-ignis\node_modules\.pnpm\postcss@8.5.1\node_modules\postcss\lib\lazy-result.js:404:17)

This lead me to this repo and to index.js file implementation.

When I added null checks for node.first my error disappeared (while Open Props are still being injected as expected).

To have a quick fix working for me, I made a fork and created custom NPM package elrh-postcss-jit-props, but I believe it would be better to have it here in the official repo.

I also added test as a POC (if you remove the null checks, it starts failing).

If I did something wrong, I am happy to hear a feedback.

Copy link

google-cla bot commented Feb 16, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Contributor

@argyleink argyleink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thanks for the added test!

@argyleink argyleink merged commit 0c98b53 into GoogleChromeLabs:main Feb 18, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants