throw new TypeError(`${relative(cwd, fileName)}: Emit skipped`)

throw new TypeError(`${relative(cwd, fileName)}: Emit skipped`)

您好,我有以下打字稿代码:

import { getConnection } from "typeorm";
import { GraphQLClient } from "graphql-request";
import got from "got";
import database from "./utils/database";
...

当我执行时:

cross-env NODE_ENV=development ts-node  src/scripts/createApp.ts http://localhost:3010/graphql

我收到以下错误:

throw new TypeError(`${relative(cwd, fileName)}: Emit skipped`)
              ^
TypeError: src/scripts/utils/database.js: Emit skipped

database.js

import { createConnection, getConnectionOptions, getConnection } from "typeorm";

export default {
  async connect(): Promise<void> {
    const connectionOptions = await getConnectionOptions(process.env.NODE_ENV);
    await createConnection({
      ...connectionOptions,
      name: "default",
    });
  },
  disconnect(): Promise<void> {
    return getConnection().close();
  },
};

哪里出错了,如何解决?

谢谢

解决办法是在tsconfig中设置这个变量

"allowJs": false,

我遇到了类似的问题,但就我而言,我需要在 tsconfig.json 中将 allowJs 设置为 true,因为我的文件中确实有一些自动生成的 js 代码我需要包含在输出中的代码库(JSON 架构文件的预编译验证器)。

确实是同目录下TS文件错误编译生成JS文件导致的问题。当我清理我的工作区时,ts-node 开始正常处理 TS 文件和那些自动生成的 JS 文件。