Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Hello I have the following typescript code:

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

When I execute:

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

I get the following error:

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

Where is the error?, How can I solve it?

Thanks

like image 609
Tlaloc-ES Avatar asked Sep 21 '20 15:09

Tlaloc-ES


2 Answers

The solution was set this variable in tsconfig

"allowJs": false,
like image 176
Tlaloc-ES Avatar answered Oct 12 '22 05:10

Tlaloc-ES


I had a similar problem but in my case, I needed allowJs to be set to true in tsconfig.json because I do have some auto-generated js-code in my codebase (pre-compiled validators for JSON Schema files) that I need to be included in the output.

The problem was indeed caused by JS files generated by incorrectly compiling TS files to JS files in the same directory. When I cleared my workspace the ts-node began to work properly with both TS files and those few auto-generated JS files.

like image 36
Xander Avatar answered Oct 12 '22 05:10

Xander