I faced the error below when I tried to add components from the shadcn ui in my Next.js app. I started this project from my other device and there everything was fine. But in my current device I got this error. I can't understand what is wrong.
npx shadcn@latest add toast
node:internal/modules/esm/resolve:204
const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);
^
Error: Cannot find package 'C:\Users\user\AppData\Local\npm-cache\_npx\d66c5096c7023bfb\node_modules\is-regexp\index.js' imported from C:\Users\user\AppData\Local\npm-cache\_npx\d66c5096c7023bfb\node_modules\stringify-object\index.js
at legacyMainResolve (node:internal/modules/esm/resolve:204:26)
at packageResolve (node:internal/modules/esm/resolve:846:14)
at moduleResolve (node:internal/modules/esm/resolve:926:18)
at defaultResolve (node:internal/modules/esm/resolve:1056:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:654:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:603:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:586:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:242:38)
at ModuleJob._link (node:internal/modules/esm/module_job:135:49) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v22.12.0
My package.json:
{
"name": "new",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev ",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@hookform/resolvers": "^3.10.0",
"@radix-ui/react-accordion": "^1.2.2",
"@radix-ui/react-alert-dialog": "^1.1.4",
"@radix-ui/react-label": "^2.1.1",
"@radix-ui/react-navigation-menu": "^1.2.3",
"@radix-ui/react-slot": "^1.1.1",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"framer-motion": "^12.0.0",
"lucide-react": "^0.473.0",
"next": "15.1.3",
"react": "^19",
"react-dom": "^19",
"react-hook-form": "^7.54.2",
"tailwind-merge": "^2.6.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.24.1"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"@types/yandex-maps": "^2.1.36",
"eslint": "^9",
"eslint-config-next": "15.1.5",
"postcss": "^8.5.1",
"tailwindcss": "^3.4.17",
"typescript": "^5"
}
}
I have tried to update node and npm current versions: node: v22.12.0 npm: 11.0.0
npm cache clean --force, clearing yourpackage-lock.json, and subsequently retrying.