TypeError: stringWidth is not a function

 node_modules\cli-table3\src\utils.js:12

This is still related to the Node.js v22 compatibility issues, but now specifically with @nestjs/cli. Let's try a complete solution:

  • First, clean your project:
     
    rm -rf node_modules
    rm yarn.lock

     

  • Update your package.json with these resolutions:
     
    package.json 
    复制代码
    {
      // ... other configs ...
      "resolutions": {
        "string-width": "4.2.3",
        "strip-ansi": "6.0.1",
        "cli-table3": "0.6.3",
        "@nestjs/cli": "10.3.2"
      }
    }
    复制代码

     

     
  • Install dependencies again:
     
    yarn install
     
  • If the issue persists, the most reliable solution is to downgrade Node.js: 
     
    nvm install 18.19.1
    nvm use 18.19.1

    Then clean and reinstall: 
    rm -rf node_modules
    rm yarn.lock
    yarn install

     

        The root cause is that NestJS CLI and its dependencies aren't fully compatible with Node.js v22 yet. Using Node.js 18 LTS is currently the most stable solution for NestJS projects. Node.js 18 is the recommended version for NestJS development and has long-term support until April 2025.
点击右上角即可分享
微信分享提示