typescript-express-starter
typescript-express-starter copied to clipboard
npm run start fails
npm run start is failing with the following error message..
Successfully compiled: 27 files, copied 4 files with swc (53.37ms) node:internal/modules/cjs/loader:936 throw err; ^
Error: Cannot find module './app.ts' Require stack:
- /home/ramanacv/work/getwise/momo/momo-be/dist/server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.
(/home/ramanacv/work/getwise/momo/momo-be/dist/server.js:5:37) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) { code: 'MODULE_NOT_FOUND', -->
Tried again and this time a different place but similar error as below -
swc src -d dist --source-maps --copy-files
Successfully compiled: 22 files, copied 2 files with swc (188.82ms) node:internal/modules/cjs/loader:936 throw err; ^
Error: Cannot find module './middlewares/error.middleware.ts' Require stack:
- /home/ramanacv/work/getwise/momo/nft-api-backend/dist/app.js
- /home/ramanacv/work/getwise/momo/nft-api-backend/dist/server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.
(/home/ramanacv/work/getwise/momo/nft-api-backend/dist/app.js:22:49) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/ramanacv/work/getwise/momo/nft-api-backend/dist/app.js', '/home/ramanacv/work/getwise/momo/nft-api-backend/dist/server.js' ]
version is the latest one from master branch. Happens for default installation as well as any other options.. Works fine in dev mode - npm run dev...
I have a similar problem. In my case, the app.js module is found, but ./middlewares/error.middleware.ts is not found.
It feels that I'm doing something wrong. I'm compiling my code with swc. My compiled output dist/server.js looks like:
│ File: dist/server.js
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ "use strict";
2 │ Object.defineProperty(exports, "__esModule", {
3 │ value: true
4 │ });
5 │ const _app = /*#__PURE__*/ _interopRequireDefault(require("./app"));
6 │ const _validateEnv = /*#__PURE__*/ _interopRequireDefault(require("./utils/validateEnv"));
7 │ const _accessoryController = require("./controllers/accessory.controller.ts");
8 │ const _trackerController = require("./controllers/tracker.controller.ts");
9 │ const _processorController = require("./controllers/processor.controller.ts");
10 │ const _ardriveController = require("./controllers/ardrive.controller.ts");
11 │ const _partnerController = require("./controllers/partner.controller.ts");
12 │ const _mintController = require("./controllers/mint.controller.ts");
13 │ const _authController = require("./controllers/auth.controller.ts");
14 │ const _discordController = require("./controllers/discord.controller.ts");
15 │ function _interopRequireDefault(obj) {
Line 5 and 6 are requireing modules without .ts suffix, but line 7 and onwards required module with .ts suffix. This is bound to fail because .ts files don't exist inside dist. Most likely, this is an swc config issue. I'll update here when I find a solution.
--
Update:
My issue was absolute paths. I had to run an additional command to convert absolute paths into relative paths.
I used the package tsc-alias. I also removed swc and used tsc to compile our codebase:
yarn tsc --project tsconfig.json && yarn tsc-alias -p tsconfig.json
There is an open issue on the swc repo regarding this bug https://github.com/swc-project/swc/issues/2725