[Bug]: `init --preset <code>` crashes with "Cannot find module 'components'" on an existing Nuxt project#1854
Reproduction
Steps to reproduce
- In an existing Nuxt 3 project already initialized with
shadcn-vue(validcomponents.json,shadcn-nuxtmodule configured), run:
(Any preset reproduces it — also tried a custom preset code, e.g.npx shadcn-vue@latest init --preset vega--preset aJRWPgW, and combinations with--template nuxt --pointer.)
Expected behavior
Either:
- Apply the preset's style/theme on top of the existing config (perhaps prompting to confirm overwrite), or
- Cleanly refuse with a clear message if re-applying a preset to an already-initialized project isn't supported (similar to how plain
initwithout--presetcorrectly reports "A components.json file already exists ... To start over, remove the components.json file and run init again.").
Actual behavior
- Preflight checks.
✔ Preflight checks.
- Verifying framework.
Something went wrong. Please check the error below for more details.
If the problem persists, please open an issue on GitHub.
Error:
Invalid components.json configuration in <project-path>.
Message:
Error: Cannot find module 'components'
Require stack:
- <project-path>/components/_index.js
### Describe the bug
### Summary
Running `npx shadcn-vue@latest init --preset <any-preset>` against an already-initialized Nuxt 3 project crashes during the "Verifying framework" step with a misleading error about an invalid `components.json`. The crash happens regardless of which preset is used (reproduced with both a custom preset code and the built-in `vega` preset), and regardless of whether `--template nuxt` is also passed. Plain `init` (no `--preset`) works correctly and safely detects the existing config.
### Environment
- `shadcn-vue`: 2.7.4 (latest on npm at time of testing)
- `shadcn-nuxt`: 2.7.4
- `nuxt`: 3.21.8 (resolved; `^3.12.2` in package.json)
- `vue`: 3.4.29
- `reka-ui`: 2.9.10
- Node: v20.19.0
- npm: 11.10.1
- OS: macOS
- Project: Nuxt 3 SPA (`ssr: false`), `"type": "module"` in package.json, `shadcn-nuxt` module configured per the official Nuxt install docs:
```ts
modules: ['shadcn-nuxt'],
shadcn: {
prefix: '',
componentDir: '@/components/ui',
},