Nx 存储库的模块解析错误

问题描述 投票:0回答:1

你好(新年快乐),

使用公司提供的 monorepo 模板,我在 monorepo 中迁移了一个 Angular 项目。我在运行 npm i 之前添加了所需的依赖项。 重新启动 vscode 以允许 nx 检测新应用程序后,我尝试使用服务运行该应用程序。 我在控制台中收到大量错误,其中:

X [ERROR] TS2792: Cannot find module './localize'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? [plugin angular-compiler]

    node_modules/@angular/localize/index.d.ts:9:28:
      9 │ import { ɵLocalizeFn } from './localize';

或:

    X [ERROR] TS2792: Cannot find module 'rxjs'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? [plugin angular-compiler]
    
        apps/digiCompta/src/app/shared/validators/async/compteTva.validator.ts:12:30:
          12 │ import { lastValueFrom } from 'rxjs';

甚至:

X [ERROR] TS-991010: 'imports' must be an array of components, directives, pipes, or NgModules.
  Value is of type '[(not statically analyzable), (not statically analyzable), (not statically analyzable), (not statically analyzable), (not statically analyzable), (not statically analyzable), (not statically analyzable), (not statically analyzable), (not statically analyzable), DownloadButtonComponent]'. [plugin angular-compiler]

    apps/digiCompta/src/app/shared/components/ebp-pdf-viewer/ebp-pdf-viewer.component.ts:34:11:
      34 │   imports: [

在项目的多个文件上。当我转到这些文件时,没有错误并且文件存在。

我不明白为什么我可以找到这些文件,但编译器说它找不到这些模块。 tsconfig.base.json 中nodeResolution设置为node,module设置为ES2022。

我删除了节点模块和 .nx 文件以重新开始,错误仍然存在 我的节点版本是 18.16.0,应该与 Angular 17 兼容。

有人熟悉这个吗? (请注意,当我直接使用 nxConsole 迁移它时,同一个项目正在运行......)

angular node-modules monorepo nx-monorepo
1个回答
0
投票

显然NX使用相对路径。这意味着您手动迁移一个项目,并且您有一堆“src/”导入,您必须更改它们。

如果您使用 nx-console 迁移项目,nx 将为您更改所有这些导入。

© www.soinside.com 2019 - 2024. All rights reserved.