react: [Bug]: Cannot find icon

Prerequisites

  • I have searched existing issues to ensure this bug hasn’t been reported already
  • I have tested this with the latest version of the components

Bug description

Error: Cannot find module '/XXX_REDACTED_XXX/node_modules/@untitledui/icons/dist/ActivityHeart' imported from /XXX_REDACTED_XXX/node_modules/@untitledui/icons/dist/index.mjs

I get the above error when implementing the following. I have followed the installation instructions closely

Steps to reproduce

  1. Install package
  2. Add the page snippet above
  3. Load page

Expected behavior

Expected there to be no runtime crash

Actual behavior

Runtime crash

Code example

import { useState } from "react"
import { TabList, Tabs } from "@/components/application/tabs/tabs"
import { Button } from "@/components/base/buttons/button"
import { SocialButton } from "@/components/base/buttons/social-button"
import { Form } from "@/components/base/form/form"
import { Input } from "@/components/base/input/input"
import { BackgroundPattern } from "@/components/shared-assets/background-patterns"
import { cx } from "@/utils/cx"

const tabs = [
	{
		id: "signup",
		label: "Sign up",
	},
	{
		id: "login",
		label: "Log in",
	},
]

export const SignupSimple = () => {
	const [password, setPassword] = useState("")

	return (
		<section className="min-h-screen overflow-hidden bg-primary px-4 py-12 md:px-8 md:pt-24">
			<div className="mx-auto flex w-full flex-col gap-8 sm:max-w-90">
				<div className="flex flex-col items-center gap-6 text-center">
					<div className="relative">
						<BackgroundPattern
							pattern="grid"
							className="absolute top-1/2 left-1/2 z-0 hidden -translate-x-1/2 -translate-y-1/2 md:block"
						/>
						<BackgroundPattern
							pattern="grid"
							size="md"
							className="absolute top-1/2 left-1/2 z-0 -translate-x-1/2 -translate-y-1/2 md:hidden"
						/>
						{/* <LogoMark size="lg" className="relative z-10 max-md:hidden" />
						<LogoMark size="md" className="relative z-10 md:hidden" /> */}
					</div>
					<div className="z-10 flex flex-col gap-2 md:gap-3">
						<h1 className="text-display-xs font-semibold text-primary md:text-display-sm">
							Create an account
						</h1>
						<p className="text-md text-tertiary">
							Start your 30-day free trial.
						</p>
					</div>
					<Tabs className="z-10 w-full">
						<TabList size="sm" fullwidth type="button-minimal" items={tabs} />
					</Tabs>
				</div>

				<Form
					onSubmit={(e) => {
						e.preventDefault()
						const data = Object.fromEntries(new FormData(e.currentTarget))
						console.log("Form data:", data)
					}}
					className="z-10 flex flex-col gap-6"
				>
					<div className="flex flex-col gap-5">
						<Input
							isRequired
							hideRequiredIndicator
							label="Name"
							type="text"
							name="name"
							placeholder="Enter your name"
							size="md"
						/>
						<Input
							isRequired
							hideRequiredIndicator
							label="Email"
							type="email"
							name="email"
							placeholder="Enter your email"
							size="md"
						/>
						<Input
							isRequired
							hideRequiredIndicator
							label="Password"
							type="password"
							name="password"
							size="md"
							placeholder="Create a password"
							onChange={setPassword}
							minLength={8}
							pattern='.*[!@#$%^&*(),.?\":{}|<>].*'
						/>
						<div className="flex flex-col gap-3">
							<span className="flex gap-2">
								<div
									className={cx(
										"flex size-5 items-center justify-center rounded-full bg-fg-disabled_subtle text-fg-white transition duration-150 ease-in-out",
										password.length >= 8 ? "bg-fg-success-primary" : "",
									)}
								>
									<svg width="10" height="8" viewBox="0 0 10 8" fill="none">
										<path
											d="M1.25 4L3.75 6.5L8.75 1.5"
											stroke="currentColor"
											strokeWidth="2"
											strokeLinecap="round"
											strokeLinejoin="round"
										/>
									</svg>
								</div>
								<p className="text-sm text-tertiary">
									Must be at least 8 characters
								</p>
							</span>
							<span className="flex gap-2">
								<div
									className={cx(
										"flex size-5 items-center justify-center rounded-full bg-fg-disabled_subtle text-fg-white transition duration-150 ease-in-out",
										password.match(/[!@#$%^&*(),.?":{}|<>]/)
											? "bg-fg-success-primary"
											: "",
									)}
								>
									<svg width="10" height="8" viewBox="0 0 10 8" fill="none">
										<path
											d="M1.25 4L3.75 6.5L8.75 1.5"
											stroke="currentColor"
											strokeWidth="2"
											strokeLinecap="round"
											strokeLinejoin="round"
										/>
									</svg>
								</div>
								<p className="text-sm text-tertiary">
									Must contain one special character
								</p>
							</span>
						</div>
					</div>

					<div className="z-10 flex flex-col gap-4">
						<Button type="submit" size="lg">
							Get started
						</Button>
						<SocialButton social="google" theme="color">
							Sign up with Google
						</SocialButton>
					</div>
				</Form>

				<div className="flex justify-center gap-1 text-center">
					<span className="text-sm text-tertiary">
						Already have an account?
					</span>
					<Button href="#" color="link-color" size="md">
						Log in
					</Button>
				</div>
			</div>
		</section>
	)
}

Browser

No response

Device type

No response

Component version

No response

Environment details

No response

Screenshots/Videos

No response

Console errors


Additional context

No response

Accessibility impact

  • This bug affects keyboard navigation
  • This bug affects screen reader users
  • This bug affects focus management
  • This bug affects color contrast or visual accessibility

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 1
  • Comments: 26 (11 by maintainers)

Most upvoted comments

I just pushed the beta changes to the latest tag. Please install the latest version:

npm i @untitledui/icons@latest

Thanks @jchonde for the feedback and suggestion 🙌 .

just tried it and it is still broken

Hi, I’m encountering the same issue in a Vite setup. In a strict ESM environment, file extensions must be explicitly specified.

In node_modules/@untitledui/icons/dist/index.mjs, the line:

import { ActivityHeart as e } from "./ActivityHeart"; should be: import { ActivityHeart as e } from "./ActivityHeart.mjs";

That should solve our issue.

@deebov

tsconfig.json:

{
	"compilerOptions": {
		"target": "ES2017",
		"lib": ["dom", "dom.iterable", "esnext"],
		"allowJs": true,
		"skipLibCheck": true,
		"strict": true,
		"noEmit": true,
		"esModuleInterop": true,
		"module": "esnext",
		"moduleResolution": "bundler",
		"resolveJsonModule": true,
		"isolatedModules": true,
		"jsx": "preserve",
		"incremental": true,
                "paths": {
                        "@/*": ["./src/*"],
                        "hls.js": ["./src/types/hls.js.d.ts"]
                },
		"types": ["node"]
       },
	"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
	"exclude": ["node_modules"]
}

eslint.config:

import { dirname } from "path"
import { fileURLToPath } from "url"
import { FlatCompat } from "@eslint/eslintrc"

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const compat = new FlatCompat({
	baseDirectory: __dirname,
})

const eslintConfig = [
	...compat.extends("next/core-web-vitals", "next/typescript"),

	{
		rules: {
			"@typescript-eslint/no-explicit-any": "off",
			"@typescript-eslint/no-unused-vars": "off",
		},
	},
]

export default eslintConfig

vitest.config.ts:

import { defineConfig } from "vitest/config"
import react from "@vitejs/plugin-react"
import { resolve } from "path"

export default defineConfig({
	plugins: [react()],
	test: {
		// Test environment
		environment: "jsdom",

		// Setup files
		setupFiles: ["./src/tests/setup.ts"],

		// Global test utilities
		globals: true,

		// Coverage configuration
		coverage: {
			provider: "v8",
			reporter: ["text", "html", "lcov"],
			exclude: [
				"node_modules/",
				"src/__tests__/",
				"**/*.d.ts",
				"**/*.config.*",
				"dist/",
				"build/",
			],
			include: ["src/**/*.{ts,tsx}"],
			thresholds: {
				global: {
					branches: 80,
					functions: 80,
					lines: 80,
					statements: 80,
				},
			},
		},

		// Test file patterns
		include: [
			"src/**/*.{test,spec}.{js,ts,jsx,tsx}",
			"src/__tests__/**/*.{js,ts,jsx,tsx}",
		],

		// Exclude patterns
		exclude: ["node_modules/", "dist/", "build/", "**/*.config.*"],

		// Test timeout
		testTimeout: 10000,

		// Mock configuration
		clearMocks: true,
		restoreMocks: true,

		// Watch options
		watch: false,

		// Retry failed tests
		retry: 1,
	},

	// Path resolution for imports
	resolve: {
		alias: {
			"@": resolve(__dirname, "./src"),
			"@/components": resolve(__dirname, "./src/components"),
			"@/hooks": resolve(__dirname, "./src/hooks"),
			"@/types": resolve(__dirname, "./src/types"),
			"@/utils": resolve(__dirname, "./src/utils"),
			"@/context": resolve(__dirname, "./src/context"),
			"@/services": resolve(__dirname, "./src/services"),
			"@/gql": resolve(__dirname, "./src/gql"),
			"@/global": resolve(__dirname, "./src/global"),
		},
	},

	// Define global variables for tests
	define: {
		"process.env.NODE_ENV": '"test"',
	},
})