小编Jor*_*rdi的帖子

将 TypeScript 应用程序发布到 Azure 时找不到模块“../lib/tsc.js”

我正在尝试将打字稿应用程序发布到在 Linux 上运行的 Azure 应用服务。我正在使用 Azure DevOps 执行此操作。我已经设置了成功的构建和发布管道,但是当我访问应用程序服务的 URL 时,我看到一条消息“:c 应用程序错误”,它引用了诊断日志。这些日志给我以下错误:

错误:找不到模块“../lib/tsc.js”

完整的错误日志

myApp@1.0.0 prod /home/site/wwwroot
> npm run build && npm run start
> myApp@1.0.0 build /home/site/wwwroot
> tsc
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module '../lib/tsc.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object. (/home/site/wwwroot/node_modules/.bin/tsc:2:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myApp@1.0.0 …
Run Code Online (Sandbox Code Playgroud)

azure node.js npm typescript azure-devops

10
推荐指数
3
解决办法
1万
查看次数

如何发送卡片旋转木马和快速回复?

我正在按照本教程在Facebook上制作对话流聊天机器人.我做了一个旋转木马并快速回复了两个单独的动作.如何发送轮播,然后快速回复同一个动作?

chatbot node.js facebook-graph-api dialogflow-es

5
推荐指数
1
解决办法
488
查看次数

在 VsCode 中使用附加调试器进行调试时在 Typescript 文件上命中断点

我正在尝试在 Docker 容器中运行的 Typescript 代码库上使用附加模式在 VsCode 中设置调试器。当我运行 docker 容器并通过 VsCode 连接调试器时,我能够命中断点,但它们总是以编译后的 Javascript 代码而不是 Typescript 代码结束。

在此输入图像描述

从图中可以看出,代码是无限循环内的简单日志语句。

索引.ts

console.log('Hello world');

while(true) {
  console.log('a')
}
Run Code Online (Sandbox Code Playgroud)

在使用 Docker 进行设置之前,我检查了文档并在本地尝试了调试器,在 Typescript 文件上命中断点时没有出现任何问题。以下是有关设置的更多信息:

启动.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Launch Program",
      "port": 9229,
      "restart": true,
      "address": "localhost",
      "remoteRoot": "./",
      "localRoot": "${workspaceFolder}",
      "outFiles": ["${workspaceFolder}/dist/**/*.js"],
      "sourceMaps": true
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

docker-compose.yml

version: '3.8'
services:
  nodeserver:
    command: nodemon --inspect=0.0.0.0:9229 ./dist/index.js
    build:
      context: ./
      dockerfile: ./build/Dockerfile
    ports:
      - '3000:3000' …
Run Code Online (Sandbox Code Playgroud)

debugging typescript docker visual-studio-code

5
推荐指数
1
解决办法
2385
查看次数

使用 Redis 实现 NestJS 外部事件总线

我正在尝试将 Nestjs 应用程序的 cqrs 设置与外部消息服务(例如 Redis)集成。我找到了一个拉取请求和一条评论,指出自 cqrs 7.0 版本以来,我应该能够将我的查询/事件/命令总线与外部服务集成。

我一直在尝试实现这一点,但我无法从 Nestjs 中找到有关该主题的太多信息。我唯一能找到的是一个过时的配置示例和 github 上的一个开放主题,用于创建有关如何实现此功能的教程。我设法通过关闭我在 github 上找到的有关此主题的有限帮助来替换默认的发布者和订阅者,但我真的不明白如何使用它来连接到外部服务,或者这是否是最佳方法这个问题。

事件总线

import { RedisEventSubscriber } from '../busses/redisEventSubscriber';
import { RedisEventPublisher } from '../busses/redisEventPublisher';
import { OnModuleInit } from '@nestjs/common';
import { ModuleRef } from "@nestjs/core";
import { CommandBus, EventBus as NestJsEventBus } from "@nestjs/cqrs";

export class EventBus extends NestJsEventBus implements OnModuleInit {

constructor( commandBus: CommandBus, moduleRef: ModuleRef) {
  super(commandBus, moduleRef);
}

onModuleInit() {

  const subscriber = …
Run Code Online (Sandbox Code Playgroud)

cqrs nestjs

4
推荐指数
1
解决办法
4043
查看次数

NestJS 基于接口注入自定义 TypeOrm 存储库

我目前正在使用 TypeOrm 完成 NestJS 的数据库集成文档。在这些文档中,有一些示例展示了如何使用 NestJS 中的 app.module 注入自定义数据库存储库。所有这些示例都使用自定义存储库的实际类型注入类。

@Injectable()
export class AuthorService {
  constructor(private authorRepository: AuthorRepository) {}
}

Run Code Online (Sandbox Code Playgroud)

此代码通过 app.modules 提供如下导入来注入:

@Module({
  imports: [TypeOrmModule.forFeature([AuthorRepository])],
  controller: [AuthorController],
  providers: [AuthorService],
})
export class AuthorModule {}
Run Code Online (Sandbox Code Playgroud)

如果您擅长针对实现进行编程,那么这很有效,但我更喜欢在我的类中使用接口。我已经在上一个问题中找到了通过 NestJS 接口注入类的解决方案,但是当我尝试像这样注入自定义存储库时,它似乎没有正确实例化并且变得未定义。

(node:16658) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'save' of undefined

因此,我假设您只能通过forFeature()app.module 中的调用注入 customRepositories,但据我所知,这不允许我使用接口进行注入。有没有其他方法可以注入自定义 TypeOrm 存储库,而无需替换所有接口来实现自定义存储库?提前致谢!

编辑

这是我当前的代码,我设法将其注入,但这仍然迫使我在每次调用构造函数时使用实现而不是接口。这主要是由于模拟而进行测试时出现的问题。

  @CommandHandler(FooCommand)
export class FooHandler
  implements ICommandHandler<FooCommand> {

  private fooRepository: IFooRepository; // Using Interface as a private property.
  private barEventBus: IEventBus;
  
  constructor(fooRepository: …
Run Code Online (Sandbox Code Playgroud)

node.js typescript nestjs

2
推荐指数
1
解决办法
2万
查看次数

通过 NestJS 将类实现注入到基于接口的抽象控制器实现中

我目前正在尝试使用 NestJS 注入进行设置,但在尝试运行服务器时遇到了错误。

我遇到的问题与我尝试将一个类注入到扩展抽象类的控制器中有关,并且我试图在构造函数中设置抽象类的属性。

控制器.ts

@Controller()
export class exampleController extends AbstractController {

  constructor(exampleClass: exampleInterface) {
    super(exampleClass);
  }

  @Get()
  getExample(): string {
    return 'Example';
  };
}
Run Code Online (Sandbox Code Playgroud)

AbstractController.ts

export abstract class AbstractController {

  private exampleClass: ExampleInterface;

  constructor(exampleClass: ExampleInterface) {
    this.exampleClass = exampleClass;
  };
Run Code Online (Sandbox Code Playgroud)

当我尝试运行我的服务器时,出现以下错误:

Error: Nest can't resolve dependencies of the ExampleController (?). Please make sure that the argument Object at index [0] is available in the AppModule context.

我已将类实现添加到 app.module 提供程序中,但即使这样,错误也会阻止我运行代码。

应用程序模块.ts

@Module({
  imports: [],
  controllers: [AppController, ExampleController],
  providers: [ExampleClass],
}) …
Run Code Online (Sandbox Code Playgroud)

node.js typescript nestjs

1
推荐指数
1
解决办法
3810
查看次数