【问题标题】:The problem of code that generated typescript (node-fluent-ffmpeg module)生成打字稿的代码问题(node-fluent-ffmpeg模块)
【发布时间】:2020-03-25 18:43:42
【问题描述】:

这是我的打字稿代码:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { FfmpegCommand } from 'fluent-ffmpeg'

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  let test

  try {
    test = new FfmpegCommand('./adventure.mkv');
  } catch (error) {
    console.log(error);

  }

  await app.listen(3000);
}

bootstrap();

生成的 Javascript 代码:

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@nestjs/core");
const app_module_1 = require("./app.module");
const fluent_ffmpeg_1 = require("fluent-ffmpeg");
function bootstrap() {
    return __awaiter(this, void 0, void 0, function* () {
        const app = yield core_1.NestFactory.create(app_module_1.AppModule);
        let test;
        try {
            test = new fluent_ffmpeg_1.FfmpegCommand('./adventure.mkv');
        }
        catch (error) {
            console.log(error);
        }
        yield app.listen(3000);
    });
}
bootstrap();
//# sourceMappingURL=main.js.map

当我运行这个应用程序时,我遇到了下一个错误:

main.ts:12 消息:“fluent_ffmpeg_1.FfmpegCommand 不是构造函数” stack:"TypeError: fluent_ffmpeg_1.FfmpegCommand is not a constructor\n at c:\nest\dist\src\main.js:20:20\n at Generator.next ()\n at fulfilled (c:\nest\dist \src\main.js:5:58)\n 在 process._tickCallback (internal/process/next_tick.js:68:7)\n 在 Function.Module.runMain (internal/modules/cjs/loader.js:834 :11)\n 在启动时 (internal/bootstrap/node.js:283:19)\n 在 bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)"

这是因为这个原始 test = new fluent_ffmpeg_1.FfmpegCommand('./adventure.mkv')。当我在 test = new fluent_ffmpeg_1('./adventure.mkv') 上更改它时,我没有错误。你知道如何解决它。如果您知道打字稿上的 ffmpeg 示例在哪里,请与我分享:)

【问题讨论】:

    标签: javascript node.js typescript ffmpeg fluent-ffmpeg


    【解决方案1】:

    这很可能是因为fluent-ffmpeg 导出其组件的方式。

    尝试像这样导入它

    import * as FfmpegCommand from 'fluent-ffmpeg
    

    import FfmpegCommand from 'fluent-ffmpeg
    

    您也可以安装打字机,在使用模块时会得到帮助

    https://www.npmjs.com/package/@types/fluent-ffmpeg

    【讨论】:

      猜你喜欢
      • 2018-10-17
      • 2016-08-17
      • 2020-09-25
      • 1970-01-01
      • 2017-05-31
      • 2016-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多