Running `dev:prepare` in the root of a module behaves differently than preparing in the playground
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 275
- Forks
- 35
- Avg merge
- 4h 42m
- Merged PRs (30d)
- 6
Description
@lewebsimple pointed out an edge case where, if a module checks for the existence of a certain file, running the dev:prepare script will fail when executed from the root of the module (via @nuxt/module-builder).
Reproduction
https://github.com/lewebsimple/nuxt-module-layers-repro
const rootDirs = getLayerDirectories().map(({ root }) => root)
let discoverMePath
for (const rootDir of rootDirs) {
if (existsSync(`${rootDir}/discover-me.txt`)) {
discoverMePath = `${rootDir}/discover-me.txt`
logger.info(`Found discover-me.txt in layer: ${rootDir}`)
break
}
}
if (!discoverMePath) {
throw new Error('Required file discover-me.txt not found in any layer directories.')
}
Steps to reproduce
- run
pnpm dev:preparein the root of the project - see that it fails
Additional context
This happens because the module's setup function runs initially without taking the playground directory into account, and only afterward does it run separately for the playground.
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the dev:prepare command and the @nuxt/module-builder prepare flow, then reproduce the failure using the linked nuxt-module-layers-repro project. Trace how the module setup function is first run and how nuxi prepare playground runs afterward. Done means preparing from the module root handles layer file discovery consistently with preparing in the playground.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nuxt, typescript
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100