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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with Next.js ? #103

Open
MatteoGauthier opened this issue Oct 19, 2021 · 8 comments
Open

How to use with Next.js ? #103

MatteoGauthier opened this issue Oct 19, 2021 · 8 comments

Comments

@MatteoGauthier
Copy link

No description provided.

@iamyuu
Copy link

iamyuu commented Oct 29, 2021

I'm trying to use it with Next.js following the directions from the Configuration section (Webpack and React) and what I got:

Screen Shot 2021-10-29 at 15 58 51

maybe I missing something 馃, check out my repo (webpack config)

@Knogobert
Copy link

Getting the same issue with unplugin-icons@0.12.18 unfortunately. Almost identical context as @iamyuu webpack config. Bumping for visibility.

@enpitsuLin
Copy link

Also same issue and I find one #46

after reading , still have no idea how to solve this

@leosuncin
Copy link
Contributor

Thanks to @enpitsuLin 's comment, I managed to make it works, you will need to:

  • Set the following config into next.config.js:
module.exports = {
  reactStrictMode: true,
  webpack(config) {
    config.plugins.push(
      require('unplugin-icons/webpack')({
        compiler: 'jsx',
        jsx: 'react',
        extension: 'jsx',
      }),
    );

    return config;
  },
};
  • Add .jsx to every icon you import, in order, next.js knows how to load the icon
import IconAccessibility from "~icons/carbon/accessibility.jsx";
import IconAccountBox from "~icons/mdi/account-box.jsx";

I not sure whether this is a desired behavior or it should be changed, but this is how it work with next.js

@iamyuu
Copy link

iamyuu commented Dec 27, 2021

Ah, we just need to add the extension (.jsx), check this commit iamyuu/nextjs-unplugin-icons-repro@a1a62f7

and voila
Screen Shot 2021-12-27 at 08 32 26

leosuncin added a commit to leosuncin/unplugin-icons that referenced this issue Dec 27, 2021
Update README.md to add instructions for Next.js

RELATED TO unplugin#103
@Knogobert
Copy link

Had to update from next@10 to next@12 for it to work. Now it runs nicely when using .jsx appended to the imported icons as @leosuncin did above. Thanks for the repo @iamyuu, that helped finding out why.

@HassanZahirnia
Copy link
Contributor

HassanZahirnia commented Feb 7, 2022

Do you guys also know how to make the Auto Importing feature work with Next.js ? Or is it not technically possible ?

@Knogobert
Copy link

Do you guys also know how to make the Auto Importing feature work with Next.js ? Or is it not technically possible ?

Haven鈥檛 tried myself yet, but I think it has something to do with getting the icons for SSR during build-time being quite tricky.
Saw some relevant thoughts on it in Anthony's discord in #unplugin-icons

Probably not the best way to paste this here, but at least you can see it without discord:
image

Hope it nudges you in the right direction. Please tell us if it worked or not and what you did 馃槂

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

No branches or pull requests

6 participants