-
Notifications
You must be signed in to change notification settings - Fork 27.7k
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
Next >14.0.1 cannot use @ant-design/icons (unexpected token 'export') #65707
Next >14.0.1 cannot use @ant-design/icons (unexpected token 'export') #65707
Comments
This comment has been minimized.
This comment has been minimized.
@nicogulo This fixed it for me ant-design/ant-design#46053 (comment) |
thanks @BaileyMillerSSI, works for me
|
Thanks guys! Took me 5 google searches to find this recent issue. |
Seems like the issue only occurs with the Page router. Was able to build successfully with the App router (14.1.1) and |
fix nextjs antd/icons npm compile error (see vercel/next.js#65707)
Fixed in |
The issue is still present with Pages Router.
transpilePackages seems to be the only option. |
Have you tried using the full path to import? For example, instead of |
@morganney well, that works (possibly, not 100% sure), but we have 100+ imports of icons in the project, and I don't want to run around replacing those to fix something which is supposed to work the standard way in the first place. And even if I do, IDE will continue to import them the standard way, which will create unnecessary friction for developers. |
@nvzoll I know for sure it works, was just pointing it out to you. You shouldn't be writing barrel files or using them from a library because they're an anti-pattern and the "benefits" aren't worth the downsides. It takes very little effort to update these imports with some tools, and very little effort to ignore your IDE prompts. You can do that or wait for maintainers to make changes. I think your IDE is prompting you that way because that's the pattern already in use. Mine seems to prompt differently, well Copilot does: ![]() |
@morganney it still requires much more effort that simply updating your next.config.js with transpilePackages list. What are downsides of this? N.B. I was referring to 'Quick Fix' menu in VS Code, not copilot. There is considerable effort for scrolling to the top of a source file and writing import manually every time you need an icon. |
Seems like optimizePackageImports option solves the issue as well when you put the list people suggest to use with transpilePackages. No visible difference in bundle analyzer output though. |
The problem is there is no Although, it might be better if it was defined like: "exports": {
".": {
"import": {
"types": "./lib/index.d.ts",
"default": "./es/index.js"
},
"require": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
}
},
"./*": {
"import": {
"types": "./lib/icons/*.d.ts",
"default": "./es/icons/*.js"
},
"require": {
"types": "./lib/icons/*.d.ts",
"default": "./lib/icons/*.js"
}
}
} |
Link to the code that reproduces this issue
https://github.com/BaileyMillerSSI/next-ant-design-demo
To Reproduce
npx create-next-app@latest
(I selected typescript, tailwind, src dir (pages), and other defaults)npm install @ant-design/icons
index.tsx
file to include an ant design iconCurrent vs. Expected behavior
Displayed error:
In an existing project I was previously on Next 14.0.1 and upgraded to 14.1.1 to resolve the published security issue. After upgrading I was unable to use ant-design/icons. This is demo is in a fresh application.
Expected:
@ant-design/icons would be usable within the base project. I have tried changing the
package.json
to be type: module and that has no affect. It seems that either or both of these are true; something was broken in next during the upgrade to >14.0.1 or ant-design/icons had a bug hidden in it that upgrading next to >14.0.1 exposed as a build error.Provide environment information
Which area(s) are affected? (Select all that apply)
create-next-app, Developer Experience, Module Resolution, Webpack
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local)
Additional context
As far I can tell this appears to be an issue with @ant-design/icons BUT next didn't complain about it until >14.0.1. With teams upgrading to resolve the security issue fixed in next 14.1.1 I suspect that more users will run into this issue.
Re:
ant-design/ant-design-icons#619
ant-design/ant-design-icons#605
The text was updated successfully, but these errors were encountered: