22

I am new to typescript and express. I am trying to run the simplest express app using ts-node-dev, but get the following error.

> ./node_modules/.bin/ts-node-dev src/index.ts                                                 16:07:40
[INFO] 16:07:42 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 4.7.2)
Compilation error in /home/lht/microservice/ticketing/auth/src/index.ts
Error: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.
    at Object.<anonymous> (/home/lht/microservice/ticketing/auth/src/index.ts:1:7)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module._compile (/home/lht/microservice/ticketing/auth/node_modules/source-map-support/source-map-support.js:568:25)
    at Module.m._compile (/tmp/ts-node-dev-hook-8101223397369532.js:69:33)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at require.extensions.(anonymous function) (/tmp/ts-node-dev-hook-8101223397369532.js:71:20)
    at Object.nodeDevHook [as .ts] (/home/lht/microservice/ticketing/auth/node_modules/ts-node-dev/lib/hook.js:63:13)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
[ERROR] 16:07:42 Error: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.

The following is my index.ts file.

import express from "express";
import { json } from "body-parser";

const app = express();
app.use(json());

app.listen(3000, () => {
  console.log("Listening on port 3000!");
});

This is my package.json file

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "ts-node src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {},
  "dependencies": {
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.35",
    "express": "^4.18.1",
    "ts-node": "^10.8.0",
    "ts-node-dev": "^1.1.8",
    "typescript": "^4.7.2"
  }
}

I wonder if there are some configurations that I am doing are wrong. Thanks in advance.

Hantong Liu
  • 555
  • 1
  • 3
  • 12
  • 1
    I just ran into the same issue for an angular project, after upgrading some dependencies. Same combination of `@types/node` and `typescript`, not using the others. Downgrading may help, that's my next move anyway – beetstra May 25 '22 at 08:59
  • 1
    @beetstra Hi, I just changed the `ts-node-dev` version to `2.0.0-0` and the error disappears. – Hantong Liu May 25 '22 at 09:12
  • Does this answer your question? [False expression: Non-string value passed to \`ts.resolveTypeReferenceDirective\` in typescript](https://stackoverflow.com/questions/72488958/false-expression-non-string-value-passed-to-ts-resolvetypereferencedirective) – Vega Jul 24 '22 at 20:04

7 Answers7

18

Just change the ts-node-dev version from 1.1.8 to 2.0.0-0 in my package.json file, then run npm install again, and the error disappears.

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "ts-node src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {},
  "dependencies": {
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.35",
    "express": "^4.18.1",
    "ts-node": "^10.8.0",
    "ts-node-dev": "^2.0.0-0",
    "typescript": "^4.7.2"
  }
}
Hantong Liu
  • 555
  • 1
  • 3
  • 12
  • 1
    This worked for me only after specifying the version of ts-node-dev in my start script in the npm package.json file, in the `"scripts"` object: `"start": "npx ts-node-dev@2.0.0-0 index.js"` – Moxley Stratton May 25 '22 at 19:55
6

I observed, why other services are working fine, except one. I found that, the failing service was getting compiled with different TS version. After I changed TS version

"typescript": "^4.6.3"

to

"typescript": "4.6.4"

that also solved the issue. enter image description here

A dev
  • 930
  • 3
  • 12
  • 27
6

I ran into this from a freshly built typeorm app (npx create-express-typescript-application my-app -t typeorm). Bumping ts-node to ^10.8.0 solved the issue.

Conner Leverett
  • 573
  • 2
  • 7
  • 21
4

A quick and easy fix is to run npm install typescript@latest ts-node@latest. The problem may be the old ts-node is incompatible with the latest typescript 4.7.x release and upgrade them fix my issue.

link89
  • 1,064
  • 10
  • 13
4

I just ran into this problem when trying to run a node server inside a yarn workspace with nodemon. Running nodemon from the workspace sub folder worked, but not from workspace root folder itself.

Script in worspace sub folder looks like this

"dev": "nodemon"

and from root folder

"dev:my-service": "yarn workspace my-service dev"

I solved it by specifically adding ts-node as a dev dependency to the "my-service" workspace

2

just change the version of ts-node

to

    "ts-node": "10.8.1",

run npm i or yarn

Yoel
  • 7,555
  • 6
  • 27
  • 59
1

Run:

npm uninstall ts-node && npm uninstall ts-node-dev

and then run:

npm i ts-node && npm i ts-node-dev --save-dev
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
  • 1
    Please read [answer] and [edit] your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post. – Adriaan Jul 22 '22 at 12:08
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](https://stackoverflow.com/help/how-to-answer). – Tyler2P Jul 26 '22 at 11:13
  • Only answer which worked for me. – Nienaber Nov 09 '22 at 07:55