Typescript error in node_modules file: error TS2792: Cannot find module '../'

Viewed 30

I've just started learning typescript. I'm getting this error while compiling ts project.

node_modules/@types/validator/lib/isBoolean.d.ts:1:23 - error TS2792: Cannot find module '../'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

1 import validator from '../';
                        ~~~~~

Compiling in ES5 doesn't throws any error but with ES6 and above gives this error.

This is my tsconfig file,

{
    "compilerOptions": {
        "target": "ES2017",
        "lib": ["DOM", "ES2017"],
        "esModuleInterop": true,
        "outDir": "dist",
        "rootDir": "./src"
    },
  "include": ["./src/"],
  "exclude": ["node_modules"],
}

This is my package.json,

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "build": "tsc",
    "tsc": "tsc --watch",
    "start": "node dist/app.js",
    "dev": "nodemon dist/app.js",
    "deploy": "tsc && node dist/app.js"
  },
  "keywords": [],
  "author": "",
  "dependencies": {
    "dotenv": "^16.0.1",
    "express": "^4.18.1",
    "mongoose": "^6.5.2",
    "postgres": "^3.2.4",
    "reflect-metadata": "^0.1.13",
    "sequelize-typescript": "^2.1.3",
    "typescript": "^4.7.4"
  },
  "devDependencies": {
    "@types/dotenv": "^8.2.0",
    "@types/sequelize": "^4.28.14",
    "@types/validator": "^13.7.6",
    "@tsconfig/node16": "^1.0.3",
    "@types/express": "^4.17.13",
    "@types/node": "^18.7.11",
    "nodemon": "^2.0.19",
    "ts-node": "^10.9.1",
    "ts-node-dev": "^2.0.0"
  }
}
0 Answers
Related