【问题标题】:NestJS: Cannot find module in dev modeNestJS:在开发模式下找不到模块
【发布时间】:2020-01-05 02:19:50
【问题描述】:

我在使用 NestJS 的应用程序的开发模式下遇到此错误。

我的配置文件如下:

export const ORM_CONFIG: TypeOrmModuleOptions = {
  keepConnectionAlive: true,
  type: 'postgres',
  host: 'localhost',
  port: 5432,
  username: 'postgres',
  password: 'postgres',
  database: 'aimbra_education',
  schema: 'security',
  synchronize: true,
  entities: [
   --Entities
  ],
  // migrations: [__dirname + '/migration/**/*.ts'],
  // subscribers: [__dirname + '/subscriber/**/*.ts'],
};

我导入到:

@Module({
  imports: [
    TypeOrmModule.forRoot(ORM_CONFIG),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

到目前为止,我无法确定为什么它在生产中工作并且在开发模式下无法查看我的修改的错误。

【问题讨论】:

  • 检查路径导入是否有前缀 "src/..." 是否有替换它以手动定位 "../../..."
  • import { Entity, PrimaryGeneratedColumn, Column } from '../../../node_modules/typeorm';我试着加了,还是不行……
  • 不适用于node_modules,请尝试使用您的服务、控制器、模块、实体文件
  • 能否提供您的tsconfig.json 文件内容?
  • 请勿发布代码、数据、错误消息等的图片 - 将文本复制或输入到问题中。 stackoverflow.com/help/how-to-ask

标签: typescript nestjs typeorm


【解决方案1】:

你可以试试这个:

例如,当我从 nestjs cli 制作一些文件时,会像这样导入他的路径:

import { UsersService } from 'src/modules/users/users.service';

像你一样给出错误。

然后当我手动替换路径时:

import { UsersService } from './users.service';

错误已修复。

【讨论】:

  • 非常感谢您的回复。但是,我想知道是否有任何方法可以更改此引用?不必手动导入...
  • 请勿发布代码、数据、错误消息等的图片 - 将文本复制或输入到问题中。 stackoverflow.com/help/how-to-ask
猜你喜欢
  • 2015-08-24
  • 2019-05-26
  • 2021-01-18
  • 2021-08-12
  • 2020-06-22
  • 1970-01-01
  • 2020-08-02
  • 1970-01-01
  • 2022-12-24
相关资源
最近更新 更多