-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could this support ESM when I set module 'ESNext' at tsconfig.json #164
Comments
+1 |
I am also facing this issue with Vitest. It appears to be an issue in the lines referencing a
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import cors from '@koa/cors';
import logger from 'koa-logger';
import errorHandler from 'koa-better-error-handler';
import koa404Handler from 'koa-404-handler';
import { router } from '@/controller/index';
const app = new Koa();
app.context.onerror = errorHandler();
app.context.api = true;
app
.use(logger())
.use(router.allowedMethods())
.use(cors())
.use(bodyParser())
.use(koa404Handler)
.use(router.routes());
export { app }; And import Router from '@koa/router';
import { SwaggerRouter, request, summary, query, path, body, tags } from 'koa-swagger-decorator';
const router = new SwaggerRouter();
const testTag = tags(['test']);
// swagger docs avaliable at http://localhost:3000/swagger-html
router.swagger({
title: 'API Server',
description: 'API DOC',
version: '1.0.0',
});
export class HealthChecker {
@request('get', '/readyz')
@summary('Check if webserver is ready to receive traffic')
@query({
verbose: {
type: 'boolean',
required: false,
default: true,
description: 'Show full output',
},
})
static async readyz(ctx) {
ctx.body = { message: 'hello world' };
}
}
router.map(HealthChecker, { doValidation: false });
export { router }; This code above works when running the Koa server with However, with Vitest file import { vi, expect, test } from 'vitest';
import request from 'supertest';
// This does not work, see https://github.com/Cody2333/koa-swagger-decorator/issues/164
import { app } from 'src/main';
test('readyz probe works', async () => {
const response = await request(app.callback()).get('/readyz');
expect(response.status).toBe(200);
expect(response.text).toBe('Hello World');
}); Returns the following errors
Please note, that |
我编译程序的js文件为 mjs, SwaggerRouter 的mapDir函数操作会报错,因为 require 语句
.pnpm\[email protected]\node_modules\koa-swagger-decorator\dist\utils.js:46
const obj = require(filepath);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module .......\router\pub.router.js from E:\project\mtd-koa\node_modules.pnpm\[email protected]\node_modules\koa-swagger-decorator\dist\utils.js not supported.
The text was updated successfully, but these errors were encountered: