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
The solution was set this variable in tsconfig
"allowJs": false,
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With