【问题标题】:Nrwl / Nx dependency error between nest and angular apps嵌套和角度应用程序之间的 Nrwl / Nx 依赖错误
【发布时间】:2021-03-11 06:55:29
【问题描述】:

我正在尝试创建一个 monorepo 项目 wirh nrwl / nx。 我按照 nx 网站上的教程进行操作,并执行以下步骤:

  • 创建一个空工作区

    npx create-nx-workspace

  • 创建一个名为 frontend 的 Angular 应用

    nx g @nrwl/angular:application

  • 创建名为 backend 的嵌套应用程序

    nx g @nrwl/nest:application frontend

我想在后端和前端之间共享所有模型接口,所以我使用命令创建了一个库:

`nx g @nrwl/workspace:lib data`

我在后端应用程序的数据库中使用@projectName/data 导入中定义的模型接口之一,我可以构建和运行后端。

导致问题的类型定义是:

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type AgentDocument = Agent & Document;

@Schema()
export class Agent{
  @Prop()
  name : string
  @Prop()
  imgUrl : string;
}

export const AgentSchema = SchemaFactory.createForClass(Agent);

经过测试,是@nestjs/mongoose 的导入导致前端在构建时出错。

我可以告诉前端在导入模型时忽略此导入吗?

【问题讨论】:

    标签: angular nestjs nrwl-nx


    【解决方案1】:

    终于找到答案了,

    问题来自用于为猫鼬定义 shema 的装饰器。

    装饰器与前端的库共享不兼容。

    这里描述了一种解决方法:

    https://github.com/nrwl/nx/issues/3322

    但由于我的模型定义中使用了 SchemaFactory 对象,它并不完全适用于猫鼬。

    相反,我重写了我的模型以删除这样的装饰器:

    import * as mongoose from 'mongoose';
    
    export interface Agent {
      name : string,
      imgUrl : string,
    }
    
    export const AgentSchema =  new mongoose.Schema({
      name : String,
      imgUrl : String,
    })
    
    export type AgentDocument = Agent & Document;
    

    【讨论】:

      猜你喜欢
      • 2019-05-23
      • 2019-07-20
      • 2021-10-20
      • 2020-07-01
      • 1970-01-01
      • 2021-08-22
      • 2022-10-19
      • 1970-01-01
      • 2019-08-19
      相关资源
      最近更新 更多