module-builder icon indicating copy to clipboard operation
module-builder copied to clipboard

Running `dev:prepare` in the root of a module behaves differently than preparing in the playground

Open cernymatej opened this issue 4 weeks ago • 3 comments

@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

  1. run pnpm dev:prepare in the root of the project
  2. 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",

cernymatej avatar Dec 21 '25 19:12 cernymatej