ysdev
ysdev

Reputation: 21

Getting ts.createNodeArray is not a function error on compiling NestJS project

Recently we migrated to node v19.7 from node v14 in our NestJS project, and doing so we updated all our packages in package.json.

But upon updating the same, now we are facing a strange error, and I am not able to figure out what might be causing it.

package.json:

{
    "name": "myproj",
    "version": "0.0.1",
    "private": true,
    "license": "UNLICENSED",
    "engines": {
        "npm": ">8.0.0 <=9.5.0",
        "node": "19.7.0"
      },
    "scripts": {
        "prebuild": "rimraf dist",
        "build": "nest build",
        "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
        "start": "nest start",
        "start-watch": "nest start --watch",
        "start-debug": "nest start --debug --watch",
        "lint": "eslint . --ext .ts -f json -o eslint-report.json",
        "lint-report": "eslint . -f node_modules/eslint-detailed-reporter/lib/detailed.js -o eslint-report.html",
        "test": "jest --coverage",
        "test:watch": "jest --watch",
        "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
        "test:e2e": "jest --config ./tests/jest-e2e.json",
        "prettier-format": "prettier --config .prettierrc **/*.ts --write",
        "prepare": "cd .. && husky install connector/.husky"
    },
    "dependencies": {
        "@google-cloud/tasks": "^3.1.1",
        "@nestjs/axios": "2.0.0",
        "@nestjs/common": "^8.4.7",
        "@nestjs/config": "^2.3.1",
        "@nestjs/core": "^8.4.7",
        "@nestjs/platform-express": "^8.4.7",
        "@nestjs/swagger": "^5.2.1",
        "@nestjs/terminus": "^8.1.1",
        "@types/dotenv": "^8.2.0",
        "@typescript-eslint/eslint-plugin": "^5.57.1",
        "@typescript-eslint/parser": "^5.57.1",
        "circular-json": "^0.5.9",
        "class-transformer": "^0.5.1",
        "class-validator": "^0.14.0",
        "dotenv": "^16.0.3",
        "eslint": "^8.37.0",
        "eslint-config-prettier": "^8.8.0",
        "eslint-detailed-reporter": "^0.9.0",
        "eslint-plugin-prettier": "^4.2.1",
        "eslint-plugin-security": "^1.7.1",
        "reflect-metadata": "^0.1.13",
        "rimraf": "^4.4.1",
        "rxjs": "^7.8.0",
        "swagger-ui-express": "^4.6.2",
        "uuid": "^9.0.0",
        "husky": "^8.0.3"
    },
    "devDependencies": {
        "@nestjs/cli": "^8.2.8",
        "@nestjs/schematics": "^9.0.0",
        "@nestjs/testing": "^8.4.7",
        "@types/express": "^4.17.17",
        "@types/jest": "^29.5.0",
        "@types/node": "^18.15.11",
        "@types/supertest": "^2.0.12",
        "@types/uuid": "^9.0.1",
        "jest": "^29.5.0",
        "lint-staged": "^13.2.0",
        "node-mocks-http": "^1.12.2",
        "prettier": "^2.8.7",
        "source-map-support": "^0.5.21",
        "supertest": "^6.3.3",
        "ts-jest": "^29.1.0",
        "ts-loader": "^9.4.2",
        "ts-node": "^10.9.1",
        "tsconfig-paths": "^4.2.0",
        "typescript": "^5.0.3",
        "husky": "^8.0.3"
    },
    "jest": {
        "moduleFileExtensions": [
            "js",
            "json",
            "ts"
        ],
        "rootDir": ".",
        "testRegex": ".*\\.spec\\.ts$",
        "transform": {
            "^.+\\.(t|j)s$": "ts-jest"
        },
        "collectCoverageFrom": [
            "**/*.(t|j)s"
        ],
        "coverageDirectory": "coverage",
        "testEnvironment": "node",
        "coveragePathIgnorePatterns": [
            "dist"
        ],
        "testTimeout": 9000
    }
}

On running, npm run start-watch, I am getting this error: ts.createNodeArray is not a function

I have already tried with deleting the node_modules, package-lock.json files, also I tried with npm clean cache --force, but still this didn't helped to resolve this issue.

Upvotes: 2

Views: 4065

Answers (2)

Ems
Ems

Reputation: 182

This is due to the version of Typescript. When looking at your logs, do you have issues with peer dependencies? If yes, you need to look at the package that is causing the problem and look at its peerDependencies. Make sure they're all compatible. Let us know if that works

Upvotes: -1

Edian Reyes
Edian Reyes

Reputation: 9

Just try and doing this

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

Seems to work for me. Hope it helps!

Upvotes: 0

Related Questions