51

I've an npm command line application that i've built not so long ago and it worked fine. Now that i've updated it, and due to changes in the versions of typescript over the period, i'm getting an error when i want to run this package which says:

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.

Here is the package.json file:

{
  "name": "initialiseur",
  "version": "4.0.4",
  "main": "src index.ts",
  "author": "@crispengari",
  "license": "MIT",
  "bin": "src/index.ts",
  "description": "THIS IS A BOILER PLATE THAT INITIALIZE A NODE EXPRESS BACKEND FOR TYPESCRIPT AND JAVASCRIPT",
  "scripts": {
    "watch": "tsc -w",
    "start": "ts-node src/index.ts",
    "dev": "nodemon dist/index.ts",
    "start:fast": "tsnd --respawn src/index.ts"
  },
  "dependencies": {
    "@types/inquirer": "^7.3.3",
    "@types/node": "^17.0.42",
    "@types/npm": "^7.19.0",
    "chalk": "^4.1.2",
    "cors": "^2.8.5",
    "cross-fetch": "^3.1.5",
    "dotenv": "^10.0.0",
    "inquirer": "^8.1.2",
    "node-fetch": "^3.2.6",
    "octokit": "^1.7.2",
    "ts-node": "^10.8.1",
    "typescript": "^4.6.5"
  },
  "devDependencies": {
    "@types/node-fetch": "^2.6.1",
    "nodemon": "^2.0.12",
    "ts-node-dev": "^2.0.0"
  },
  "bugs": {
    "url": "https://github.com/CrispenGari/initialiseur/issues"
  },
  "homepage": "https://github.com/CrispenGari/initialiseur#readme",
  "keywords": [
    "node.ts",
    "node.js",
    "typescript",
    "ts",
    "nodejs-backend",
    "javascript",
    "js",
    "express",
    "backend"
  ]
}

When i'm testing it locally by running:

npm start

# or 
yarn start

Everything is working fine, but after publishing it to npm to start it i run the following command:

npx initialiseur

Then I'm getting the error from a command line. The whole error is as follows:

C:\Users\crisp\AppData\Roaming\npm\node_modules\initialiseur\node_modules\typescript\lib\typescript.js:42536
        ts.Debug.assert(typeof typeReferenceDirectiveName === "string", "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.");
                 ^
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.resolveTypeReferenceDirective (C:\Users\crisp\AppData\Roaming\npm\node_modules\initialiseur\node_modules\typescript\lib\typescript.js:42536:18)
    at C:\Users\crisp\AppData\Roaming\npm\node_modules\ts-node\src\resolver-functions.ts:131:51
    at Array.map (<anonymous>)
    at Object.resolveTypeReferenceDirectives (C:\Users\crisp\AppData\Roaming\npm\node_modules\ts-node\src\resolver-functions.ts:130:31)
    at actualResolveTypeReferenceDirectiveNamesWorker (C:\Users\crisp\AppData\Roaming\npm\node_modules\initialiseur\node_modules\typescript\lib\typescript.js:116673:163)
    at resolveTypeReferenceDirectiveNamesWorker (C:\Users\crisp\AppData\Roaming\npm\node_modules\initialiseur\node_modules\typescript\lib\typescript.js:116973:26)
    at processTypeReferenceDirectives (C:\Users\crisp\AppData\Roaming\npm\node_modules\initialiseur\node_modules\typescript\lib\typescript.js:118455:31)
    at findSourceFileWorker (C:\Users\crisp\AppData\Roaming\npm\node_modules\initialiseur\node_modules\typescript\lib\typescript.js:118340:21)
    at findSourceFile (C:\Users\crisp\AppData\Roaming\npm\node_modules\initialiseur\node_modules\typescript\lib\typescript.js:118195:26)
    at processImportedModules (C:\Users\crisp\AppData\Roaming\npm\node_modules\initialiseur\node_modules\typescript\lib\typescript.js:118601:25)

From the above error i can tell that the problem maybe comming from typescript, I'v tried changing version of typescript but still it's not working. In my src/index.ts it looks as follows:


#!/usr/bin/env ts-node
import path from "path";
import inquirer from "inquirer";
import { writeFile, readFile } from "fs/promises";

....


crispengari
  • 7,901
  • 7
  • 45
  • 53
  • 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:03
  • It's a `ts-node` `typescript` version mismatch. Credit below. – Ben Racicot Oct 04 '22 at 19:41

17 Answers17

38

Running npm install -g ts-node@latest fixed it for me. I needed to update my globally installed ts-node version.

Nils Reichardt
  • 3,195
  • 2
  • 18
  • 28
29

To reiterate previous answers for yarn users:

yarn add -D ts-node@latest solved it for me. These are my versions now:

"ts-node": "^10.9.1",
"typescript": "^4.7.4"

The top answer probably shouldn't recommend a downgrade.


Edit

If you continue to face issues, try deleting your node_modules folder and reinstalling by running yarn.

If it still doesn't work, you may need to add these versions to your resolutions field in package.json, and then run yarn install --force.

{
  "resolutions": {
    "ts-node": "^10.9.1",
    "typescript": "^4.7.4"
  }
}

However, I consider this a bit of a temporary measure, and I wouldn't recommend leaving the resolutions in forever.

Fernando Rojo
  • 2,633
  • 19
  • 17
  • I had to delete node_modules folder and package-lock.json for those versions to work at all. Thanks man. – Karli Ots Aug 09 '22 at 17:25
  • You typically don't want to delete your lock file. A better solution is likely a yarn resolution to fix the version. – Fernando Rojo Aug 14 '22 at 17:43
  • This worked for me, without deleting package-lock or node_modules. Had to remove my global ts-node installation as well. – Hsjakobsen Aug 24 '22 at 08:42
18

Getting the same as of a couple of days.

Reverting ts-node to v10.6.0 fixes it for me.

Paul Etscheit
  • 493
  • 1
  • 6
  • 16
  • 4
    It's been a few weeks since this answer, and now updating both packages to latest is probably a better solution than reverting to an older package (`npm i typescript@latest ts-node@latest`), but do what's best for your codebase. Credit to answers below. – TJBlackman Jul 13 '22 at 17:20
  • I've tried old version, new versions.. No difference - the error is present. – Alexander Feb 23 '23 at 15:04
13

It is hapening in typescript 4.7. I lowered my typescript to 4.6.4, and the error disappeared

9
  • Update the Typescript as @alex-totolici has suggested: npm i typescript@latest

  • And update the ts-node: npm i ts-node@latest

YakovL
  • 7,557
  • 12
  • 62
  • 102
  • 1
    and if any of `typescript`, `ts-node` were installed globally, use `-g` flag – YakovL Jul 19 '22 at 09:20
  • These advices are everywhere, but it does not help in my situation. However I noticed I have incompatible requirement in "ng-packagr": `"typescript": ">=4.4.0 <4.7"`. I.e. it wants an old version of typescript. Don't know if things like that could be the reason of that error. – Alexander Feb 23 '23 at 15:00
5

Remeber to distinguish between global ts-node and package ts-node; You have to use npx to run local ts-node

> npx ts-node ...

Anyway, this is what I finally found after 30 mins of repeatedly rm -rf node_nodules and yarn add ts-node@latest.

bbbbbbbboat
  • 443
  • 3
  • 11
  • Dude this was the missing piece for me. I had my dependencies on the same version as everyone else and it wasn't working. But I had a global ts-node installed which was old and was calling that. Since I was fine with updating my global ts-node package, I just ran `npm install -g ts-node@latest` to fix it. – DJSDev Sep 20 '22 at 14:16
4

These changes in the package.json worked for me.

"ts-node": "~10.7.0"

"typescript": "~4.6.4"

Fazil Khan
  • 66
  • 4
3

Try updating all you packages including typescript

To update typescript: npm i typescript@latest

Here is a package to check for updates: https://www.npmjs.com/package/npm-check-updates

Alex Totolici
  • 318
  • 2
  • 14
2

Running this solved the issue:

npm install --save-dev ts-node@latest     
Tt789
  • 35
  • 4
1

Using ts-node-dev version 2.0.0 fixes this problem. Note you'll have to manually specify the version as by default this version may not get installed.

Pranav Asthana
  • 892
  • 1
  • 9
  • 21
1

In my case the reason was the outdated version of ng-packagr: I've upgraded from Angular 13 to Angular 15. But forgot to update ng-packagr.

Alexander
  • 1,152
  • 1
  • 16
  • 18
0

I had the same issue, and already ran the latest versions of typescript and ts-node.

Updating nodemon npm install -g nodemon@latest solved it for me!

0

I just figure out that the problem was coming from inquirer import when i commented the import it just worked:

// import inquirer from "inquirer";

I suspect that the inquirer types and my current typescript version are not lining up. So you must as well try to debug by commenting imports if the above answers did not work for you.

crispengari
  • 7,901
  • 7
  • 45
  • 53
0

I don't know exactly why but the problem comes from a @type package, you can find a line similar to this /// <reference types='node' /> if you delete it won't have this problem anymore

-1

Try newer version of typescript and ts-node .

Prakash Bhandari
  • 549
  • 8
  • 16
-1

i have the same problem but it works fine now with below version:

  "ts-node": "~10.7.0",
     "typescript": "~4.6.4",
Sa Lesanan
  • 57
  • 4
  • 2
    What is the additional insight which this answer post contributes? "Use newer versions" is already covered by other existing answers. – Yunnosch Sep 05 '22 at 13:08
-1

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

I still see the issue even after updating the version of Typescript & ts-node with latest versions.

  • 1
    Welcome to StackOverflow. What you've provided is not an answer. If also have the same problem, consider upvoting the question instead. – Mark Stosberg Oct 07 '22 at 15:13