111

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"
  },
Mohamed Anser Ali
  • 1,269
  • 2
  • 8
  • 13
  • I got this error when I had "ts-node" listed in my "devDependencies" but forgot to run "yarn install" / "npm install". – Benny Code Jul 19 '22 at 14:29
  • Having the same error after updating typescript from 4.6 to 4.7 on a frontend Vue2 project . I don't have ts-node as a dependency. – walox Nov 16 '22 at 09:11

14 Answers14

157

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

Alexander
  • 16,091
  • 5
  • 13
  • 29
Houssem Hichri
  • 1,577
  • 1
  • 2
  • 2
  • 1
    I experienced this issue on ts-node 9.1.1 and this fix worked – Woodz Jun 16 '22 at 02:23
  • 3
    I switched TS from `4.6.4` to `4.8.0-dev.20220618` and the error starts to occur. upgrading `ts-node` from `10.7.0` to `10.8.1` doesn't fix the error. – Pablo LION Jun 19 '22 at 21:20
  • 1
    One of my dependencies used `ts-node` though I did not directly. I added `ts-node` as a dev dependency at `^10.9.1` and that fixed for me. – calvinf Jul 15 '22 at 19:53
  • As this appears to be a bug in ts-node, can someone please post a link to an open bug with them, so we can track its progress? – sorin Aug 01 '22 at 09:26
  • I used `ts-node@9.1.1` in my personal project. In recent days, I faced the same issue, which is perfectly fixed by this solution. – tronx.dev Nov 28 '22 at 13:31
77

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

Pablo LION
  • 1,294
  • 6
  • 20
21

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

Nathanael
  • 330
  • 3
  • 6
  • 3
    which requires me to update to webpack 5, which unfortunately causes a lot of other problems for the time being – Flion Jul 25 '22 at 15:35
  • I came here after upgrading to TS 4.9 (and react to v18) and this solution (after all the other upgrades mentioned in other answers) helped – Michal Maťovčík Jan 10 '23 at 08:09
6

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

A Jar of Clay
  • 5,622
  • 6
  • 25
  • 39
4

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

Do try updating ts-loader also....

The command is: npm install ts-loader@latest

Tapas Vashi
  • 231
  • 2
  • 5
3

yarn add -D ts-node or npm install --save-dev ts-node solves the problem

BoyePanthera
  • 546
  • 5
  • 10
2

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/, 
        },
Javlonbek
  • 46
  • 5
2

Using typeorm 0.2.43 & typescript 4.9.5

Problem fixed on my code upgrading ts-node to 10.9.1 (lastest version by now)

npm install ts-node@latest -D
1

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

Farouk Mhamdi
  • 311
  • 2
  • 8
1

Using the following versions worked for me.

ts-node 10.8.1 & node 14.17.3

Lenzman
  • 1,177
  • 18
  • 30
1

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

Michael Eliot
  • 831
  • 8
  • 18
1

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.

0

updating ts-loader and ts-node to latest , resolved in my case

npm install -D ts-loader@latest ts-node@latest
Victor Eronmosele
  • 7,040
  • 2
  • 10
  • 33
Rasul
  • 1
  • 2
0

It is not a TS error. Upgrading to the latest version is the recommended path.

However, in my app moving to the latest version of TS did not provide significant advantages hence, I downgraded the TS to the version v4.2.4 from v4.9.5 to resolve the issue temporarily.

In case your situation is similar to mine (other high priorities) then delay TS upgrade strategy for time being if it is not posing quality issues.

parth
  • 1
  • 2