相关文章推荐
含蓄的红薯  ·  PermissionDeniedError: ...·  1 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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"
                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, 2022 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, 2022 at 9:11
                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, 2022 at 21:20
                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, 2022 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 1, 2022 at 9: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, 2022 at 13:31

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.

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

which requires me to update to webpack 5, which unfortunately causes a lot of other problems for the time being – Flion Jul 25, 2022 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 at 8:09

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

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.

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
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.