首页 > 解决方案 > 使用 create-react-app 和 Yarn 2.0 进行本地开发

问题描述

我很难设置一个 React 项目来使用我的 Node 模块的本地版本。我像往常一样使用

npx create-react-app my-app

我使用切换到 Yarn 2.0

yarn set version berry

我还将 Yarn 配置为使用node-modules而不是 PnP。

我尝试使用链接我的依赖项

yarn link ../../my-cool-module

我在 App.js 中使用我的模块添加了一些代码,但是当我运行时yarn build出现类似错误

./src/App.js
Cannot find module: 'my-cool-module'. Make sure this package is installed.

package.json 片段由更新yarn link

 "resolutions": {
    "my-cool-module": "portal:/path/to/the/my-cool-module"
  }

我在网上看到很多人称赞这个新的 Shiny yarn 2.0 协议portal,但是有没有人设法让它工作?!

标签: reactjscreate-react-appyarnpkg-v2

解决方案


推荐阅读