ljlm0402 / typescript-express-starter

📘 Quick and Easy TypeScript Express Starter
http://npm.im/typescript-express-starter
MIT License
2.71k stars 419 forks source link

npm run start fails #194

Open Ramanagetwise opened 1 year ago

Ramanagetwise commented 1 year ago

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:

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:


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...

shivekkhurana commented 1 year ago

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