@@ -125,6 +125,23 @@ function renderTemplateToFile(templateFilePath: string, data: Record<string, unk
125125 * Writes only when the file does not exist or dependencies actually change (to avoid race issues on CI).
126126 * Returned value indicates whether a write occurred.
127127 */
128+ function ensureWorkspaceIsolation ( reactRootPath : string ) {
129+ // Create an empty yarn.lock so Yarn 4 treats this directory as a standalone
130+ // project root instead of traversing up into the parent monorepo workspace.
131+ const yarnLockPath = join ( reactRootPath , 'yarn.lock' ) ;
132+ if ( ! existsSync ( yarnLockPath ) ) {
133+ writeFileSync ( yarnLockPath , '' ) ;
134+ }
135+
136+ // Create a minimal .yarnrc.yml so that Yarn uses node-modules linker and
137+ // does not inherit the parent workspace's yarnPath (which is a relative path
138+ // that would not resolve correctly from the tmp directory).
139+ const yarnrcPath = join ( reactRootPath , '.yarnrc.yml' ) ;
140+ if ( ! existsSync ( yarnrcPath ) ) {
141+ writeFileSync ( yarnrcPath , 'nodeLinker: node-modules\n' ) ;
142+ }
143+ }
144+
128145function upsertReactRootPackageJson ( params : {
129146 reactRootPath : string ;
130147 react : ReactVersion ;
@@ -133,6 +150,7 @@ function upsertReactRootPackageJson(params: {
133150} ) : { wrote : boolean ; pkgPath : string } {
134151 const { reactRootPath, react, dependencies, logger } = params ;
135152 mkdirSync ( reactRootPath , { recursive : true } ) ;
153+ ensureWorkspaceIsolation ( reactRootPath ) ;
136154 const reactRootPkgPath = join ( reactRootPath , 'package.json' ) ;
137155
138156 const basePkg : PackageJson = {
0 commit comments