False expression: Non-string value passed to `ts.resolveTypeReferenceDirective` in typescript

When I try to run ts-node-dev./index.ts, I get the below error, I updated my typescript and ts-node-dev, ts-node but this error keeps on popping if I remove dependencies that have @types/XXXX(eg:@types/express) it is working fine.

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.

    "dependencies": {
"ajv": "^8.9.0",
"axios": "^0.27.1",
"exceljs": "^4.3.0",
"express": "^4.17.1",
"json2csv": "^5.0.7",
"moment-timezone": "^0.5.33",
"mysql": "^2.18.1",
"mysql-utilities": "^1.1.3",
"q": "^1.5.1",
"ts-node": "^10.8.0",
"ts-node-dev": "^2.0.0",
"typescript": "^4.7.2",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5"
},
"devDependencies": {
"@types/chai": "^4.2.22",
"@types/express": "^4.17.11",
"@types/jest": "^27.4.0",
"@types/mocha": "^9.0.0",
"@types/mysql": "^2.15.20",
"@types/node": "^15.6.1",
"chai": "^4.3.4",
"jest": "^27.4.7",
"mocha": "^9.1.2",
"ts-jest": "^27.1.3"
},
50147 次浏览

Upgrading to "ts-node": "10.8.1" solved the issue for me.

Try downgrading to typescript@4.6.x. This may be needed if this issue occurs without ts-node installed.

Solution

My problem was caused by upgrading typescript from 4.6 to ^4.7, and I did this to fix it:

# With NPM
npm install ts-node-dev@latest ts-node@latest


# With yarn
yarn upgrade ts-node-dev@latest ts-node@latest


# With pnpm
pnpm up ts-node-dev@latest ts-node@latest

I was using "ts-node": "^10.7.0", and "ts-node-dev": "^1.1.8", after upgrading both dev-deps, the issue was solved.

Why

TS 4.7 upgrades the resolution mode (see the last line). Given that the ts-node and ts-node-dev are using the old resolution mode internally, updating them to the later version, to be exact ts-node@>=10.8.0 and ts-node-dev@>=2, fixes this problem.

This chapter is added for @KhachaturStepanyan

TL;DR

After upgrading only "ts-node"(from Houssem Hichri's answer), the error remained, because I was using "ts-node-dev": "^1.1.8".

I was upgrading typescript to 4.7.4 and I fixed this by upgrading ts-loader to 9.3.1.

probably it's an node versioning error, so try to update your node version and check package.json file

Using the following versions worked for me.

ts-node 10.8.1 & node 14.17.3

I had the same issue. I replaced ts-loader with babel-loader in webpack configs

before:

{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader"
},
],
exclude: /node_modules/,
},
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: /node_modules/,
},

after:

{
test: /\.tsx?$/,
use: [
{
loader: "babel-loader"
},
],
exclude: /node_modules/,
},
{
test: /\.ts$/,
loader: 'babel-loader',
exclude: /node_modules/,
},

My issue was that I had an out of date global version of ts-node that was causing issues, even though the one in the local project was fine. I resolved it by uninstalling the global version and using the npx version.

npm uninstall -g ts-node

npx ts-node app.ts

If none of the above issues works for you....

Do try updating ts-loader also....

The command is: npm install ts-loader@latest

Since no one mentioned it, I was upgrading versions of a package, and somewhere between upgrading and building this error popped up. I couldn't figure out if the previous answers were useful, so I just nuked rm package-lock.json after verifying that my package.json has the dependencies I want. After building again with a new package-lock.json, my project succeeded.