【问题标题】:throw new TypeError(`${relative(cwd, fileName)}: Emit skipped`)throw new TypeError(`${relative(cwd, fileName)}: Emit skipped`)
【发布时间】:2021-01-07 16:55:15
【问题描述】:

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

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();
  },
};

错误在哪里?,我该如何解决?

谢谢

【问题讨论】:

    标签: node.js typescript ts-node


    【解决方案1】:

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

    "allowJs": false,
    

    【讨论】:

      【解决方案2】:

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

      该问题确实是由错误地将TS文件编译成同目录下的JS文件生成的JS文件造成的。当我清除工作区时,ts-node 开始与 TS 文件和那几个自动生成的 JS 文件一起正常工作。

      【讨论】:

      • 这似乎是 tsconfig 的问题。我设法删除了 rootDir,它工作得很好。
      猜你喜欢
      • 2022-01-06
      • 2020-08-16
      • 1970-01-01
      • 2019-04-20
      • 1970-01-01
      • 2017-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多