Trying to get up and running with an Express app, but running into an error when `npm run start`

Attached the errors as a txt file.
15 Replies
j_slno
j_slno5d ago
try to set declarations to false and strict to true in your tsconfig
k5o5
k5o5OP5d ago
No luck there. Here's my tsconfig
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"declaration": false,
"strict": true,
},
"lib": ["es2015"]
}
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"declaration": false,
"strict": true,
},
"lib": ["es2015"]
}
j_slno
j_slno5d ago
can you try to exclude node_modules
k5o5
k5o5OP5d ago
Excuse me, but how exactly do I do that? Sort of new to Express and TS
j_slno
j_slno5d ago
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"declaration": false,
"strict": true,
"lib": ["es2015"] // this should be inside compilerOptions
},
"exclude": ["node_modules"]
}
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"declaration": false,
"strict": true,
"lib": ["es2015"] // this should be inside compilerOptions
},
"exclude": ["node_modules"]
}
k5o5
k5o5OP5d ago
Thanks for your patience. Unfortunately, still no luck
k5o5
k5o5OP5d ago
For a bit more context, I followed the instructions for setting up better auth from here https://www.better-auth.com/docs/installation And the instructions for node+express+ts from here: https://www.digitalocean.com/community/tutorials/setting-up-a-node-project-with-typescript
Installation | Better Auth
Learn how to configure Better Auth in your project.
How To Set Up a Node Project With Typescript | DigitalOcean
Writing server-side JavaScript can be challenging as a codebase grows. TypeScript is a typed (optional) super-set of JavaScript that can help with building a…
j_slno
j_slno5d ago
"Note that CommonJS (cjs) isn't supported. Use ECMAScript Modules (ESM) by setting "type": "module" in your package.json or configuring your tsconfig.json to use ES modules." You cant use commonjs.
k5o5
k5o5OP4d ago
@j_slno hello, I changed to modules, and I'm still getting the same errors tsconfig:
{
"compilerOptions": {
"module": "es2015",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist"
},
"lib": ["es2015"]
}
{
"compilerOptions": {
"module": "es2015",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist"
},
"lib": ["es2015"]
}
And in package.json I have "type": "module",
j_slno
j_slno4d ago
Have you tried to delete node_modules and your lock file and reinstall again? lib should be inside compilerOptions also make sure to set declarations to false
k5o5
k5o5OP4d ago
@j_slno Thanks for your help. I just created the entire project from scratch, and did some more research, and I finally got the server to run it seems. I do, however have a new issue which is this
No overload matches this call.
The last overload gave the following error.
Argument of type '(req: Request<{}, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>) => Promise<Response<any, Record<...>, number>>' is not assignable to parameter of type 'Application<Record<string, any>>'.
Type '(req: Request<{}, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>) => Promise<Response<any, Record<...>, number>>' is missing the following properties from type 'Application<Record<string, any>>': init, defaultConfiguration, engine, set, and 63 more.ts(2769)
No overload matches this call.
The last overload gave the following error.
Argument of type '(req: Request<{}, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>) => Promise<Response<any, Record<...>, number>>' is not assignable to parameter of type 'Application<Record<string, any>>'.
Type '(req: Request<{}, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>) => Promise<Response<any, Record<...>, number>>' is missing the following properties from type 'Application<Record<string, any>>': init, defaultConfiguration, engine, set, and 63 more.ts(2769)
No description
lonelyplanet
lonelyplanet4d ago
Try assign types from express import {Request, Response} from 'express'; then use (req:Request,res:Response)
k5o5
k5o5OP4d ago
Just solved the issue. Was using express 4 but express types 5, and apparently they are not compatible
lonelyplanet
lonelyplanet4d ago
Well glad you fixed it

Did you find this page helpful?