首页 > 解决方案 > 纱线工作区和角度“找不到'node_modules'目录。”

问题描述

在尝试将项目切换到使用纱线工作区后,我似乎无法让角度编译器命令工作。我尝试使用 yarn dlx 命令来使用应该为运行该命令的特定工作区安装的 angular 编译器版本,但是 angular/yarn 会引发错误

 YN0000: > yarn dlx -p @angular/cli ng build --prod && npm run merge && npm run clean
➤ YN0000: 
➤ YN0000: ➤ YN0000: ┌ Resolution step
➤ YN0000: ➤ YN0061: │ request@npm:2.88.2 is deprecated: request has been deprecated, see https://github.com/request/request/issues/3142
➤ YN0000: ➤ YN0061: │ uuid@npm:3.4.0 is deprecated: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
➤ YN0000: ➤ YN0061: │ har-validator@npm:5.1.5 is deprecated: this library is no longer supported
➤ YN0000: ➤ YN0000: └ Completed in 1s 312ms
➤ YN0000: ➤ YN0000: ┌ Fetch step
➤ YN0000: ➤ YN0000: └ Completed
➤ YN0000: ➤ YN0000: ┌ Link step
➤ YN0000: ➤ YN0007: │ @angular/cli@npm:12.0.3 must be built because it never did before or the last one failed
➤ YN0000: ➤ YN0000: └ Completed in 1s 218ms
➤ YN0000: ➤ YN0000: Done with warnings in 2s 664ms
➤ YN0000: 
➤ YN0000: Your global Angular CLI version (12.0.3) is greater than your local version (10.0.8). The local Angular CLI version is used.
➤ YN0000: 
➤ YN0000: To disable this warning use "ng config -g cli.warnings.versionMismatch false".
➤ YN0000: An unhandled exception occurred: Cannot locate the 'node_modules' directory.
➤ YN0000: See "/private/var/folders/_1/5253gc4s28l4740x6hm0b8500000gp/T/ng-mBJIHY/angular-errors.log" for further details.
➤ YN0000: Done in 20s 310ms

我尝试寻找解决此问题的方法,但我是第 2 版纱线的新手,我不明白我需要研究哪种类型的解决方案来解决此问题。

标签: angularyarn-workspaces

解决方案


I found the answer. When working with angular and yarn workspaces, make sure that in your yarnrc.yml file you have:

nodeLinker: node-modules

This will allow for angular to resolve the modules needed. Currently this is an issue with angular.


推荐阅读