Next.js Discord

Discord Forum

How do I deploy a typescript express app?

Unanswered
Violet-green Swallow posted this in #help-forum
Open in Discord
Violet-green SwallowOP
I used to deploy express apps written in JS in the past with no problem, but now when I try deploying an express application written in TypeScript my serverless function crashes and I get the following error.

Error: Cannot find package 'express' imported from /var/task/app.js
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:892:9)
    at moduleResolve (node:internal/modules/esm/resolve:985:20)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:936:12)
    at defaultResolve (node:internal/modules/esm/resolve:1178:79)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
...


This is how my vercel.json file looks.

{
  "builds": [
    {
      "src": "*.ts",
      "use": "@vercel/node"
    }
  ],
  "rewrites": [
    {
      "source": "/(.*)",
      "destination": "app.ts"
    }
  ]
}


How do I fix this issue?

~[#10713](https://github.com/vercel/vercel/discussions/10713)

13 Replies

is express in your pakage.json?
Violet-green SwallowOP
yup
This is the application I'm trying to deploy - https://github.com/therealsujitk/github-download-page/tree/main
Dunker
deploy your backend to another service
first seperate each as folders like client, server
Violet-green SwallowOP
but why isn't this working? I've used express in vercel in the past
This is the first time I'm trying it with typescript, previously I used const express = require('express');
Dunker
hmm, use same, when TS complains ignore it with @ts-ignore
Violet-green SwallowOP
I changed everything to require() and had to remove "type": "module" from package.json. I also had to downgrade got since it doesn't support require() anymore and it works now.
It's resolved for now, but I'd like to know why it doesn't work with import.
Asiatic Lion
sup i deployed a vite+express done in typescript no errors but i got 404
where do i put the vercel.json file?
i have the folder project with 2 folders, server and client