Typescript: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`

Viewed 16943

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

....


13 Answers

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

Getting the same as of a couple of days.

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

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.

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

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

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

These changes in the package.json worked for me.

"ts-node": "~10.7.0"

"typescript": "~4.6.4"

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.

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!

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.

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

  "ts-node": "~10.7.0",
     "typescript": "~4.6.4",

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.

Try newer version of typescript and ts-node .

Related