primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Primeicons issues with Tailwind 4 and postcss

Open blackat opened this issue 1 year ago • 31 comments

Describe the bug

Hello, I have update to PrimeNG 19.0.5 and Angular 19.1.4. I have seen that PrimeFlex has been deprecated in favour of Tailwind 4.

I have followed the Tailwind page to install the required dependencies and I started to have issues with Primeicons:

Application bundle generation failed. [0.855 seconds]

✘ [ERROR] Could not resolve "./fonts/primeicons.eot" [plugin angular-css-resource]

    src/styles.css:554:11:
      554 │   src: url('./fonts/primeicons.eot');
          ╵            ~~~~~~~~~~~~~~~~~~~~~~~~


✘ [ERROR] Could not resolve "./fonts/primeicons.eot?#iefix" [plugin angular-css-resource]

    src/styles.css:555:11:
      555 │   src: url('./fonts/primeicons.eot?#iefix') format('embedded-open...
          ╵            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


✘ [ERROR] Could not resolve "./fonts/primeicons.woff2" [plugin angular-css-resource]

    src/styles.css:555:77:
      555 │ ...d-opentype'), url('./fonts/primeicons.woff2') format('woff2'),...
          ╵                      ~~~~~~~~~~~~~~~~~~~~~~~~~~


✘ [ERROR] Could not resolve "./fonts/primeicons.woff" [plugin angular-css-resource]

    src/styles.css:555:126:
      555 │ ...rmat('woff2'), url('./fonts/primeicons.woff') format('woff'), ...
          ╵                       ~~~~~~~~~~~~~~~~~~~~~~~~~


✘ [ERROR] Could not resolve "./fonts/primeicons.ttf" [plugin angular-css-resource]

    src/styles.css:555:173:
      555 │ ...ormat('woff'), url('./fonts/primeicons.ttf') format('truetype'...
          ╵                       ~~~~~~~~~~~~~~~~~~~~~~~~


✘ [ERROR] Could not resolve "./fonts/primeicons.svg?#primeicons" [plugin angular-css-resource]

    src/styles.css:555:223:
      555 │ ...etype'), url('./fonts/primeicons.svg?#primeicons') format('svg');
          ╵                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After many tests I have seen the issues happens when I add tailwindcss and postcss. I have also clone the PrimeNG repo and noticed you use Tailwind 3 and the configuration file that is not anymore used in version 4.

For the time being I am progressing with the migration of the app from PrimeNG 17 to 19 excluding Primeicons, do you have please a workaround for this issue?

Thanks in advance

Pull Request Link

No response

Reason for not contributing a PR

  • [x] Lack of time
  • [x] Unsure how to implement the fix/feature
  • [x] Difficulty understanding the codebase
  • [ ] Other

Other Reason

No response

Reproducer

https://stackblitz.com/edit/github-kukoe1tg?file=package.json,.postcssrc.json,.gitignore

Environment

  • PrimeNG 19.0.5
  • Angular 19.1.4
  • Tailwind 4
  • OSX Sequoia 15

Angular version

19.1.4

PrimeNG version

v19

Node version

22.6.0

Browser(s)

Chrome Version 132.0.6834.83 (Official Build) (arm64)

Steps to reproduce the behavior

Basically the steps described here

  1. ng new my-project --style css
  2. cd my-project
  3. npm install tailwindcss @tailwindcss/postcss postcss --force
  4. install primeicons
  5. ng serve

Attention! Consider also this issue opened by Tailwind team on Angular CLI 19.

Expected behavior

ng serve command runs fine, no errors, and I can see the primeicons

blackat avatar Feb 01 '25 11:02 blackat

I managed to get it working with a simple update. After installing the required packages using:
npm install tailwindcss @tailwindcss/postcss postcss --force

after that install the tailwindcss-primeui plugin using: npm i tailwindcss-primeui

I updated my styles.scss file as follows:

@plugin 'tailwindcss-primeui';
@layer tailwind, primeng;

@layer tailwind {
  @import "tailwindcss";
}

Next, I added a new file at the project root called .postcssrc.json to configure postcss with the following content:

{
    "plugins": {
        "@tailwindcss/postcss": {}
    }
}

then in the providePrimeNG function, I updated the cssLayer.order as follows:

providePrimeNG({
      theme: {
        preset: Aura,
        options: {
          darkModeSelector: '.dark',
          cssLayer: {
            name: 'primeng',
            order: 'tailwind, primeng',
          },
        },
      },
    }),

After these changes, everything worked as expected.

Note: This was done on a new project. For existing projects, additional configuration may be required depending on the project's complexity. I recommend following the Tailwind migration guide.

YoussefSell avatar Feb 02 '25 13:02 YoussefSell

@YoussefSell Thanks for your quick input. I faced the same issue earlier when I created a new Angular 17 / Tailwind 4 project.

I have updated the styles.scss files like you suggested, however i don't know where the providePrimeNG is...?

Can you please clarify. Thanks

AymKh avatar Feb 02 '25 14:02 AymKh

Hello @YoussefSell, thanks a lot lot for your answer, I have tried both in an empty project and in my current project I am migrating.

Empty project generated by Angular CLI (here I use css)

my styles.css:

@import "tailwindcss";
@import "primeicons/primeicons.css";

@layer tailwind, primeng;

@layer tailwind {
  @import "tailwindcss";
}

my app.config.ts:

import {ApplicationConfig, provideZoneChangeDetection} from '@angular/core';
import {provideRouter} from '@angular/router';

import {routes} from './app.routes';
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
import {providePrimeNG} from 'primeng/config';
import Aura from '@primeng/themes/aura'

export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({eventCoalescing: true}), provideRouter(routes),
    provideAnimationsAsync(),
    providePrimeNG({
      theme: {
        preset: Aura,
        options: {
          darkModeSelector: '.dark',
          cssLayer: {
            name: 'primeng',
            order: 'tailwind, primeng',
          },
        },
      },
    })
  ],
};

Issues

  • Same as before if I include @import "primeicons/primeicons.css";
  • I also have Misplaced @import error warning in the styles.css

Current project I am migrating (here I use scss)

my styles.scss:

@import "tailwindcss";
@import "primeicons/primeicons.css";

@layer tailwind, primeng;

@layer tailwind {
  @import "tailwindcss";
}

Issues

  • I get a warning around the @import deprecation and I cannot use @use
    • Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.
  • I still get the same error as before

blackat avatar Feb 02 '25 15:02 blackat

@YoussefSell Thanks for your quick input. I faced the same issue earlier when I created a new Angular 17 / Tailwind 4 project.

I have updated the styles.scss files like you suggested, however i don't know where the providePrimeNG is...?

Can you please clarify. Thanks

I think the providePrimeNG() is available from PrimeNG 18+.

blackat avatar Feb 02 '25 15:02 blackat

@AymKh providePrimeNG() is available in PrimeNG 18+

YoussefSell avatar Feb 02 '25 22:02 YoussefSell

@blackat to use primeicons, after installing it, update your styles.css as follow:

@use "primeicons/primeicons.css";
@plugin 'tailwindcss-primeui';
@layer tailwind, primeng;

@layer tailwind {
  @import "tailwindcss";
}

it worked from me

YoussefSell avatar Feb 02 '25 22:02 YoussefSell

Hello @YoussefSell, yes it works now!!! really cool 🚀

Sorry if I exploit a bit more your time:

  • I still have the issue with @import: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0. is there something else I could use?
  • @plugin 'tailwindcss-primeui' is not only till Tailwind 3?

Thanks again for your help, much appreciated 😄

Update

I have noticed that this part

@layer tailwind {
   @import "tailwindcss";
}

override something (not sure if the right term), basically all the m-x classes and similars have not effect. I have remove it and I can see the icons and the m-x classes work now.

Not sure what that @layer does, but it seems to me some classes of Tailwind do not work correctly.

blackat avatar Feb 03 '25 04:02 blackat

@YoussefSell Your fix worked but what I have noticed is if using in the styleclass for a primeng component it loses specifity. So now I have to use !class in the styleclass.

Example

<p-button (onClick)="click()" [text]="true" styleClass="!p-0 !flex !items-end">

whereas before I could use <p-button (onClick)="click()" [text]="true" styleClass="p-0 flex items-end">

like referenced here https://primeng.org/tailwind

Any ideas on that?

JohnFredMeyer avatar Feb 06 '25 19:02 JohnFredMeyer

Well to help others since the documentation for tailwind integration is no longer correct. Ill post this to help.

@import "tailwindcss/preflight.css" layer(tailwind-base); @import "tailwindcss/theme.css" layer(tailwind-theme); @import "tailwindcss/utilities.css" layer(tailwind-utilities); @plugin 'tailwindcss-primeui';

@layer tailwind-base, tailwind-theme, tailwind-utilities, primeng;

@theme { --spacing: .25rem }

this
  .config
  .theme
  .set({
    preset: MyPreset,
    options: {
      prefix: "",
      darkModeSelector: "null",
      cssLayer: {
        name: "primeng",
        order: "tailwind-base, tailwind-theme, primeng, tailwind-utilities"
      }
    }
  });

If you use the imports like above they will be named the same and it will work just like before. Also since the switch to v4 takes something like w-* equals now width: calc(var(--spacing * *) you have to set a spacing value. To keep the same for an existing project you have to set spacing to .25rem. Lastly if you have these in you code

.test{ background-color: blue; }

.example { @apply font-bold test }

it now has to be converted to

// should be lowercase utility below but this editor keeps changing to capital? @utility test { background-color: blue; }

@utility example{ @apply font-bold test }

easiest way to accomplish this with old project is copy the css classes into utilities. This will also maintain specifity if you want to override primeng styleclass. If you don't want to do that just change the order in the css layer.

JohnFredMeyer avatar Feb 07 '25 11:02 JohnFredMeyer

I think it's easiest to just use the layers that Tailwind already defines for us. Out of the box they provide an empty components layer that is meant exactly for what we need.

styles.css:

@import "tailwindcss";
@plugin "tailwindcss-primeui";

app.config.ts:

export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({eventCoalescing: true}),
    provideRouter(routes),
    provideAnimationsAsync(),
    providePrimeNG({
      theme: {
        preset: Aura,
        options: {
          cssLayer: {
            name: 'components'
          },
        },
      },
    })
  ],
};

makuko avatar Feb 07 '25 12:02 makuko

@makuko thats much cleaner and worked great for me. Didn't know about the @component layer

JohnFredMeyer avatar Feb 07 '25 13:02 JohnFredMeyer

This problem appeared to me when I wrote this code in the style.scss file

problem is :

Unknown at rule @pluginscss(unknownAtRules)

🔹 style.scss:

@plugin 'tailwindcss-primeui';
@layer tailwind, primeng;

@layer tailwind {
  @import "tailwindcss";
}
}

AmrTarek7 avatar Feb 08 '25 07:02 AmrTarek7

@makuko which version of Tailwindcss are you using? I think with version 4 @plugin "tailwindcss-primeui"; is not anymore valid but only in case of version 3.

blackat avatar Feb 08 '25 17:02 blackat

@blackat I'm using v4. The @plugin syntax is part of the new CSS-first configuration and I think it didn't exist before. According to the docs it's meant for backwards compatability. So in the long run tailwindcss-primeui needs to be refactored.

makuko avatar Feb 08 '25 18:02 makuko

This problem appeared to me when I wrote this code in the style.scss file

problem is :

Unknown at rule @pluginscss(unknownAtRules)

🔹 style.scss:

@plugin 'tailwindcss-primeui'; @layer tailwind, primeng;

@layer tailwind { @import "tailwindcss"; } }

I have the same issue, using angular 19 primeng 19 and tailwindcss 4. I'm using css as styles not scss.

DaniRamirezVaquero avatar Feb 11 '25 08:02 DaniRamirezVaquero

I'm using:

  • Angular 19.1.4
  • tailwindcss 4.0.3
  • primeng 19.0.6
  • tailwindcss-primeui 0.4.0

I fixed in this way:

  • style.scss:
@use "tailwindcss";

@use "primeicons/primeicons.css";

@plugin "tailwindcss-primeui";

@tailwind utilities;

claarzu avatar Feb 11 '25 13:02 claarzu

I'm using:

  • Angular 19.1.4
  • tailwindcss 4.0.3
  • primeng 19.0.6
  • tailwindcss-primeui 0.4.0

I fixed in this way:

  • style.scss:
@use "tailwindcss";

@use "primeicons/primeicons.css";

@plugin "tailwindcss-primeui";

@tailwind utilities;

Worked for me - you also need to follow: https://tailwindcss.com/docs/installation/framework-guides/angular

Plus install - Primeui tailwind: https://primeng.org/tailwind

Thanks claarzu

mbuchner avatar Feb 16 '25 23:02 mbuchner

I'm using:

  • "@angular/core": "^19.1.6"
  • "tailwindcss": "^4.0.6"
  • "primeng": "^19.0.6"
  • tailwindcss-primeui 0.4.0
  • "primeicons": "^7.0.0"
  • "postcss": "^8.5.2"
  • "@tailwindcss/postcss": "^4.0.6"

I fixed in this way:

  • style.scss:
@use "tailwindcss";
@use "primeicons/primeicons.css";
@plugin "tailwindcss-primeui";
@tailwind utilities;
  • app.config.ts:
export const appConfig: ApplicationConfig = {
...
...
providePrimeNG({
 theme: {
  preset: Aura,
  },
 }
}
  • .postcssrc.json:
{
  "plugins": {
    "@tailwindcss/postcss": {}
  }
}

NOTE: i guess tailwind.config.js file is not longer needed. Thanks to @claarzu

dazes97 avatar Feb 17 '25 20:02 dazes97

I think it's easiest to just use the layers that Tailwind already defines for us. Out of the box they provide an empty components layer that is meant exactly for what we need.

styles.css:

@import "tailwindcss"; @plugin "tailwindcss-primeui"; app.config.ts:

export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({eventCoalescing: true}), provideRouter(routes), provideAnimationsAsync(), providePrimeNG({ theme: { preset: Aura, options: { cssLayer: { name: 'components' }, }, }, }) ], };

It seems to work with primeng and tailwindcss. But the original error is still present when adding primeicons:

@import "tailwindcss";
@plugin "tailwindcss-primeui";
@import "primeicons/primeicons.css";

alaindeurveilher avatar Feb 17 '25 23:02 alaindeurveilher

You don't want to import a .css file directly here with tailwind's postcss, otherwise it's just going to dump the .css file into your styles so the file paths are going to be completely wrong; everything is going to be relative to your styles.css file. Import the prime icons as a style in your build and there will be no issues.

Setup

You need these packages:

npm install @tailwindcss/postcss postcss --save-dev
npm install tailwindcss tailwindcss-primeui

Changes

.postcssrc.json

{
  "plugins": {
    "@tailwindcss/postcss": {
    }
  }
}

app.config.ts

    ...
    providePrimeNG({
      theme: {
        preset: YourThemeNameHere,
        options: {
          // nothing needed here unless you want to add stuff like tailwind overrides
          // see: https://primeng.org/tailwind#override
          // (basically i'm saying nothing needs to change here unless you have a particular setup)
        }
      },
    })
  ],

./src/styles.css (or wherever it is)

@import "tailwindcss";
@plugin "tailwindcss-primeui";
/* your other stuff below */

angular.json

{
  "projects": {
    "name-of-app": {
      "architect": {
        "build": {
          "options": {
            "styles": [
              "src/styles.css",
              "primeicons/primeicons.css"
            ],
        // ...
        "test": {
          "options": {
            "styles": [
              "src/styles.css",
              "primeicons/primeicons.css"
            ],

Savestate2A03 avatar Feb 18 '25 08:02 Savestate2A03