![](/img/trans.png)
[英]How to test a custom module running node-fluent-ffmpeg (an async module)?
[英]The problem of code that generated typescript (node-fluent-ffmpeg module)
這是我的打字稿代碼:
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 不是構造函數”堆棧:“TypeError:fluent_ffmpeg_1.FfmpegCommand 不是構造函數\\n at c:\\nest\\dist\\src\\main.js:20:20\\n at Generator.next ()\\n at fulled (c:\\nest\\dist\\src\\main.js:5:58)\\n at process._tickCallback (internal/process/next_tick.js:68:7)\\n at 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)"
這是因為這個原始測試 = new fluent_ffmpeg_1.FfmpegCommand('./adventure.mkv') 。 當我在 just test = new fluent_ffmpeg_1('./adventure.mkv')上更改它時,我沒有錯誤。 你知道怎么解決嗎。 如果您知道打字稿上的 ffmpeg 示例在哪里,請與我分享:)
這很可能是因為fluent-ffmpeg
導出其組件的方式。
嘗試像這樣導入它
import * as FfmpegCommand from 'fluent-ffmpeg
或者
import FfmpegCommand from 'fluent-ffmpeg
你也可以安裝typings,在使用模塊時你會得到幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.