egg 在 Yarn 2 下无法运行
最小可复现仓库https://github.com/duanzheng/test-egg-yarn-v2
复现步骤,错误日志以及相关配置- 安装最新版的 Yarn,并按照官方教程开启 Yarn 2 模式
- 在项目根目录执行 yarn install
- 执行 yarn dev,此时会报错
Error: egg is not found in /Users/tony/Documents/myCode/egg-test/node_modules at assertAndReturn (/Users/tony/Documents/myCode/egg-test/.yarn/cache/egg-utils-npm-2.4.1-a2af25016f-2.zip/node_modules/egg-utils/lib/framework.js:66:9) at Object.getFrameworkPath (/Users/tony/Documents/myCode/egg-test/.yarn/cache/egg-utils-npm-2.4.1-a2af25016f-2.zip/node_modules/egg-utils/lib/framework.js:49:10) at DevCommand.formatArgs (/Users/tony/Documents/myCode/egg-test/.yarn/cache/egg-bin-npm-4.14.1-b4aed5d5cd-2.zip/node_modules/egg-bin/lib/cmd/dev.js:89:28) at formatArgs.next (<anonymous>) at onFulfilled (/Users/tony/Documents/myCode/egg-test/.yarn/cache/co-npm-4.6.0-dd9caee4b9-2.zip/node_modules/co/index.js:65:19) at /Users/tony/Documents/myCode/egg-test/.yarn/cache/co-npm-4.6.0-dd9caee4b9-2.zip/node_modules/co/index.js:54:5 at new Promise (<anonymous>) at co (/Users/tony/Documents/myCode/egg-test/.yarn/cache/co-npm-4.6.0-dd9caee4b9-2.zip/node_modules/co/index.js:50:10) at toPromise (/Users/tony/Documents/myCode/egg-test/.yarn/cache/co-npm-4.6.0-dd9caee4b9-2.zip/node_modules/co/index.js:118:63) at next (/Users/tony/Documents/myCode/egg-test/.yarn/cache/co-npm-4.6.0-dd9caee4b9-2.zip/node_modules/co/index.js:99:29)
看了一下报错的 egg-utils/lib/framework.js 的代码,代码中写死了会去找 node_modules 中的文件,然而 Yarn 2 默认是没有 node_modules 的,这个也是我们需要的新特性。
相关环境信息- 操作系统:macOS 10.15.4
- Node 版本:12.16.2
- Egg 版本:2.15.1