-
-
Notifications
You must be signed in to change notification settings - Fork 545
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
Import bug in Next.js (v13.4.13) #1482
Comments
@gregberge Can you post your nextjs config? |
error with 0.264.0
https://nextjs.org/docs/messages/module-not-found Import trace for requested module: next.config:
|
Same for me, |
Just went to ncu --upgrade and I saw the issue occur when upgrading from / to the following versions. lucide-react ^0.263.1 → ^0.264.0 |
same for me here the list of icons not found: lucide-react: ^0.264.0
|
There are more! |
same here, seems to happen with all icons on next |
I have just downgraded to |
@abdelhameedhamdy I'm a bit surprised with your issue, after seeing your Nextjs Config. transform: {
// Special aliases
'(SortAsc|LucideSortAsc|SortAscIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/arrow-up-narrow-wide!lucide-react',
'(SortDesc|LucideSortDesc|SortDescIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/arrow-down-wide-narrow!lucide-react',
'(Verified|LucideVerified|VerifiedIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/badge-check!lucide-react',
'(Slash|LucideSlash|SlashIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/ban!lucide-react',
'(CurlyBraces|LucideCurlyBraces|CurlyBracesIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/braces!lucide-react',
'(CircleSlashed|LucideCircleSlashed|CircleSlashedIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/circle-slash-2!lucide-react',
'(SquareGantt|LucideSquareGantt|SquareGanttIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/gantt-chart-square!lucide-react',
'(SquareKanbanDashed|LucideSquareKanbanDashed|SquareKanbanDashedIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/kanban-square-dashed!lucide-react',
'(SquareKanban|LucideSquareKanban|SquareKanbanIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/kanban-square!lucide-react',
'(Edit3|LucideEdit3|Edit3Icon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/pen-line!lucide-react',
'(Edit|LucideEdit|EditIcon|PenBox|LucidePenBox|PenBoxIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/pen-square!lucide-react',
'(Edit2|LucideEdit2|Edit2Icon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/pen!lucide-react',
'(Stars|LucideStars|StarsIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/sparkles!lucide-react',
'(TextSelection|LucideTextSelection|TextSelectionIcon)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/text-select!lucide-react',
// General rules
'Lucide(.*)':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/{{ kebabCase memberMatches.[1] }}!lucide-react',
'(.*)Icon':
'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/{{ kebabCase memberMatches.[1] }}!lucide-react',
'*': 'modularize-import-loader?name={{ member }}&from=default&as=default&join=./icons/{{ kebabCase member }}!lucide-react',
}, So we need to update this list, but I'm not sure if this hardcoding is the best way if I'm honest. |
As of writing, options to get around this are:
Is this right @ericfennis? |
This is a Vercel issue, not a lucide issue. export { default as ArrowUpNarrowWide } from './dist/esm/icons/arrow-up-narrow-wide.js'; But this would increase bundle size and load time which is a no brainer to avoid. |
We should just generate those aliases as - export { default as LucideSparkles, default as LucideStars, default as Sparkles, default as SparklesIcon, default as Stars, + default as StarsIcon } from './icons/sparkles.js';
+ export { default as LucideSparkles, default as Sparkles } from './icons/sparkles.js';
+ export { default as LucideStars, default as Stars } from './icons/stars.js';
+++ ./icons/stars.js
+ export { default } from "./sparkels.js" |
@jguddas It would be great if Lucide React can add these aliases. Otherwise we'll have to maintain a list in Next.js to optimize the imports. |
I am currently facing this issue with Next.js 13.4.13 and lucide-react version 0.264.0
My workaround: Downgraded lucide react to version 0.263.1 and it is working like expected. |
If I import directly from the esm modules, I don't get the error: import { Menu } from "lucide-react/dist/esm/lucide-react"; "lucide-react": "^0.264.0",
"next": "13.4.13", |
@jacobawebb Yes I think so. |
Created a fix: vercel/next.js#53697 |
That fix will break earlier versions of IMO this hard coded list of overrides is a mess for anyone to maintain... For example, I was just upgrading to @jguddas plan to add these in lucide seems more stable than maintaining a list in next that works for specific lucide versions |
Adding my voice here. I would have never known the sweet spot is 0.263.1 without this discussion thread. |
Seems like |
@juliusmarminge Only 3 versions won't work with these changes (v0.262.0, v0.263.0, v0.263.1). |
### What? Fixing outdated import mapping with the latest `lucide-react` changes. See [lucide-icons/[email protected]](https://github.com/lucide-icons/lucide/releases/tag/v0.264.0) Closes: lucide-icons/lucide#1482 ### Why? Import mapping was outdated ### How? By updating the default config and the tests. ## Notes Maintainer here from @lucide-icons. To this day I didn't know the Nextjs default config file has predefined hardcoded modularize imports. I was a bit surprised that there is a default mapping for libraries that could change in the future like Lucide. I'm not in favor of this hardcoded "modularize imports", because this creates a hard dependency on libraries. With Lucide, we still have not reached 1.0 and will sometimes rename icons and add aliases for them. So issues will occur in the future, and constantly updating this config doesn't feel right. Is there, not a better way? Like for example, a package exposing a config file containing the import mapping? This way import map will automatically be in sync with changes in a package. Let me know what you think of this.
It will also break Sanity live previews and Serverless functions on Vercel. |
Packages version
Getting Error while importing Icons
import { PackageCheck, PackageMinus, type LucideIcon } from 'lucide-react';
export type Icon = LucideIcon
export const Icons = {
logo: PackageMinus
}
"use client"
import Link from "next/link";
import { useSelectedLayoutSegment } from "next/navigation"
import { useState } from "react";
import { Icons } from "@/components/Icons";
interface MainNavProps {
}
export function MainNav() {
const segment = useSelectedLayoutSegment()
const [mobileMenu, setMobileMenu] = useState<boolean>(false)
return (
<div className="flex gap-6 md:gap-10">
<Link href="/" className="hidden items-center space-x-2 md:flex">
<Icons.logo />
</Link>
</div >
)
} Error : Module not found: Can't resolve '/Users/sonu/Projects/NextJS/memoir/node_modules/lucide-react/dist/cjs/icons/package-minus'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./components/Icons.tsx
./components/MainNav.tsx Downgrading lucide-react to 0.263.1 is working. |
+1 |
PR vercel/next.js#53697 got merged and will be available in canary versions first. |
@ericfennis I feel like this thread makes people aware of the issue, how to currently get around it and how it's going to be solved going forward. Time to close? 🎉 |
@jacobawebb I was thinking to wait for the next canary release. Until then this issue is still active with current NextJS versions. |
@ericfennis How can I deploy a project that has this error? |
For now downgrade lucide-react to pnpm add [email protected] |
I've done that but it still give the error on Vercel |
Same problem
|
@NandiyaLive, you probably just let the
Even when you specify the version with npm/pnpm/yarn on the install command, and even if you add the |
This issue will be resolved in next version of NextJS |
🎉 |
Prerequisites
Step to reproduce
Import icon in a Next.js v13.4.13 (latest)
Actual behavior
I see an error when importing the icon.
Any message or error
It works well on v0.263.x, I suspect a bug in the new ESM export.
The text was updated successfully, but these errors were encountered: