Home > database >  Cannot find name 'CallSite' for Error stacktrace in Node.js and TypeScript
Cannot find name 'CallSite' for Error stacktrace in Node.js and TypeScript

Time:12-29

I have this code:

Error.prepareStackTrace = function (
  error: Error,
  stack: Array<CallSite>,
) {
  return self.parse(fiber, error, stack)
}

I am trying to get the CallSite to import, but its not finding it from @types/node.

enter image description here

tsconfig.json

{
  "compilerOptions": {
    "module": "ES6",
    "target": "ES6",
    "lib": ["es2020"],
    "outDir": "host",
    "rootDir": "make",
    "sourceMap": true,
    "moduleResolution": "node",
    "strictNullChecks": true,
    "strict": true,
    "esModuleInterop": true,
    "noUncheckedIndexedAccess": true,
    "baseUrl": "./make",
    "paths": {
      "~": ["."]
    },
    "types": ["node"],
    "typeRoots": ["node_modules/@types"],
    "noImplicitAny": true
  },
  "include": ["make"],
  "exclude": ["node_modules"]
}

package.json

{
  "type": "module",
  "scripts": {
    "build": "tsc && tsc-alias",
    "watch": "concurrently --kill-others \"tsc -w\" \"tsc-alias -w\"",
    "lint": "eslint --ext .ts ./make",
    "lint:fix": "npm run lint -- --fix",
    "test": "node --no-warnings --loader @esbuild-kit/esm-loader host/build"
  },
  "devDependencies": {
    ...
    "@types/node": "^18.11.17",
    "ts-node": "^10.9.1",
    "tsc-alias": "^1.8.2",
    "typescript": "^4.9.4"
  }
}

Any ideas why it's not finding it, or how to find it?

CodePudding user response:

CallSite is in the namespace NodeJS if you check the sources.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0cb820adf9389fbda935c850f58eb2c5e5973515/types/node/globals.d.ts#L125

So you need to change your declaration like this.

Error.prepareStackTrace = function (
    error: Error,
    stack: Array<NodeJS.CallSite>,
  • Related