You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 17环境下创建文件夹中yarn/npm包安装后消失问题

Where Did My Yarn-Installed React Packages Go?

Hey there, I've run into this exact issue a few times when working with monorepos or fresh project directories—let's break down what's probably happening and how to track down your missing react and react-dom packages:

1. You're likely in a Yarn Workspace (Monorepo Setup)

Since you're working inside bundler-app/packages/myfolder, it's common for the root bundler-app directory to have a Yarn Workspaces configuration. This setup tells Yarn to install all dependencies from sub-packages into a single node_modules folder at the root of your project (to save space and share dependencies across packages).

  • Head up to the bundler-app directory and check if there's a node_modules folder there—your react and react-dom packages are almost certainly inside it.
  • Verify this by checking the root package.json for a workspaces field, which will look something like this:
    {
      "workspaces": [
        "packages/*"
      ]
    }
    

This is intentional behavior for monorepos, so don't worry—your packages are safe, just centralized!

2. Your myfolder Directory Doesn't Have a package.json

Yarn needs a package.json file in the directory where you run yarn add to know where to install local dependencies. If you didn't initialize a package first, Yarn will walk up the directory tree and install the packages in the nearest parent directory that has (or can create) a package.json.

  • Check if packages/myfolder has a package.json file. If not:
    1. Run yarn init -y inside myfolder to generate a basic package.json
    2. Re-run yarn add react react-dom—this time, Yarn will create a node_modules folder directly in myfolder and install the packages there.
  • If you already checked the root bundler-app directory, you'll probably find a package.json there with react and react-dom listed in its dependencies (Yarn created it automatically when you ran the first install).

3. (Unlikely) Accidental Global Install

While yarn add defaults to local installation, it's worth ruling out a global install just in case. Run yarn global dir to see where Yarn stores global packages—if you don't see react there, you can cross this off your list.

Quick Recap

9 times out of 10, your packages are either in the root bundler-app/node_modules (thanks to workspaces) or in a parent directory's node_modules because you didn't initialize a package.json in myfolder. Follow the steps above, and you'll find them in no time!

内容的提问来源于stack exchange,提问作者faraz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:09:30