6

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

Tlaloc-ES
  • 4,825
  • 7
  • 38
  • 84

3 Answers3

11

The solution was set this variable in tsconfig

"allowJs": false,
Tlaloc-ES
  • 4,825
  • 7
  • 38
  • 84
3

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.

Xander
  • 1,114
  • 2
  • 9
  • 18
0

On my side it was due to version after update issue solved

yarn add ts-node --dev
# npm i --save-dev ts-node
Daniel Lazar
  • 101
  • 8