Reputation: 713
I'm working on a react typescript application. Because of 'top level await' issues, I want to change my target and module to 'es2017' and 'esnext' respectively. Changing the target to 'es2017' works fine, but the moment I change the module to 'esnext' my app crashes on startup.
The problem is an express route that no longer works:
Route.get() requires a callback function but got a [object Undefined]
Here's the specific code in my server.ts
const {all_users} = require("./controllers/UserController");
express.get("/users", all_users);
UserController.ts:
import "reflect-metadata";
import {createConnection} from "typeorm";
import {User} from "../entities/User";
exports.all_users = function(req, res) {
createConnection().then(async connection => {
const users = await connection.manager.find(User);
res.json({users});
}).catch(error => console.log(error));
};
tsconfig.json:
{
"compilerOptions": {
"lib": [
"es5",
"es6"
],
"target": "es2017",
"module": "esnext",
"moduleResolution": "node",
"outDir": "./build",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitAny": false,
"strictNullChecks": true,
"jsx": "react",
"resolveJsonModule": true
},
"include": [
"src/**/*.ts"
]
}
Is this a known problem with esnext?
Upvotes: 0
Views: 466
Reputation: 713
I had to change the declaration of all_users
to:
export function all_users(req, res) {
Upvotes: 1