抛出新的TypeError`$ {relativecwd,fileName}:跳过跳过`

问题描述

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

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,
,

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

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