Debasis Tripathy
Debasis Tripathy

Reputation: 3

Getting no-extraneous imports issue while starting typescript project i

At first project was running fine even with the extraneous import issue. But now server is not starting because I added some code into "eslint.json" file with some modification in rules "rules": { "node/no-extraneous-import":[ "error", { "devDependencies": false, "optionalDependencies": false, "peerDependencies": false } ] }

my tsconfig.json details are below

{
  "compilerOptions": {
    "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
    /* Modules */
    "module": "commonjs" /* Specify what module code is generated. */,
    "rootDir": "./src" /* Specify the root folder within your source files. */,
    "lib": ["ES2016"],
    "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */ /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */,
    "resolveJsonModule": true /* Enable importing .json files. */ /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */,
    /* JavaScript Support */
    "allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
    "checkJs": true /* Enable error reporting in type-checked JavaScript files. */ /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */,
    "outDir": "./build" /* Specify an output folder for all emitted files. */ /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */,
    "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
    "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
    // "preserveSymlinks": true,                         /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
    "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
    /* Type Checking */
    "strict": true /* Enable all strict type-checking options. */,
    "noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
    "strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */ /* Disable error reporting for unreachable code. */,

    /* Completeness */
    // "skipDefaultLibCheck": true,                      /* Skip type checking .d.ts files that are included with TypeScript. */
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  }
}

enter image description here

Also I am facing issue with this error if everything else is okay with the eslintrc.json file, though I am using google lint or "gts/lint"

My package.json values are here

{
  "name": "sociopub",
  "version": "1.0.0",
  "main": "src/index.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon src/index.ts",
    "start": "npm run build & node build/index.js",
    "build": "rimraf ./build & tsc",
    "lint": "gts lint",
    "clean": "gts clean",
    "compile": "tsc",
    "fix": "gts fix",
    "prepare": "npm.cmd run compile",
    "pretest": "npm.cmd run compile",
    "posttest": "npm.cmd run lint"
  },
  "keywords": [],
  "author": "Debasis Tripathy",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "@aws-sdk/types": "^3.577.0",
    "@types/axios": "^0.14.0",
    "@types/chalk": "^2.2.0",
    "@types/cors": "^2.8.17",
    "@types/express": "^4.17.21",
    "@types/express-session": "^1.18.0",
    "@types/express-validator": "^3.0.0",
    "@types/jsonwebtoken": "^9.0.6",
    "@types/mongoose": "^5.11.97",
    "@types/morgan": "^1.9.9",
    "@types/multer": "^1.4.11",
    "@types/node": "20.11.5",
    "@types/nodemailer": "^6.4.15",
    "@types/otp-generator": "^4.0.2",
    "@types/qs": "^6.9.15",
    "@types/swagger-jsdoc": "^6.0.4",
    "@types/swagger-ui-express": "^4.1.6",
    "axios": "^1.7.2",
    "cors": "^2.8.5",
    "gts": "^5.3.0",
    "morgan": "^1.10.0",
    "otp-generator": "^4.0.1",
    "qs": "^6.12.1",
    "rimraf": "^5.0.7",
    "ts-node": "^10.9.2",
    "typescript": "^5.4.5"
  },
  "dependencies": {
    "@sendgrid/mail": "^8.1.3",
    "@types/bcrypt": "^5.0.2",
    "@types/dotenv": "^8.2.0",
    "@types/helmet": "^4.0.0",
    "@types/passport": "^1.0.16",
    "@types/passport-facebook": "^3.0.3",
    "@types/passport-google-oauth20": "^2.0.16",
    "aws-sdk": "^2.1631.0",
    "bcrypt": "^5.1.1",
    "cloudinary": "^2.2.0",
    "dotenv": "^16.4.5",
    "express": "^4.19.2",
    "express-session": "^1.18.0",
    "express-validator": "^7.1.0",
    "helmet": "^7.1.0",
    "jsonwebtoken": "^9.0.2",
    "mongoose": "^8.4.1",
    "multer": "^1.4.5-lts.1",
    "nodemailer": "^6.9.13",
    "nodemon": "^3.1.2",
    "passport": "^0.7.0",
    "swagger-jsdoc": "^6.2.8",
    "swagger-ui-express": "^5.0.0"
  }
}

enter image description here

I have tried changing a lot of compilerOptions and package.json but still these issues are there. My eslintrc.json data is below

{
  "extends": "./node_modules/gts/"
}

enter image description here

I want to resolve this anyhow . My backend server is throwing these errors.

I tried changing all the modules and resloveModuleResolutions etc but still not working. I am trying to change the compatibility of all the packages so that server will start without giving those issues.

The error it is giving is

C:\Users\debasis.tripathy\Desktop\files\socioPub\node_modules\ts-node\dist\index.js:851
            return old(m, filename);
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\debasis.tripathy\Desktop\files\socioPub\node_modules\chalk\source\index.js from C:\Users\debasis.tripathy\Desktop\files\socioPub\src\index.ts not supported.
Instead change the require of index.js in C:\Users\debasis.tripathy\Desktop\files\socioPub\src\index.ts to a dynamic import() which is available in all CommonJS modules.
    at require.extensions.<computed> [as .js] (C:\Users\debasis.tripathy\Desktop\files\socioPub\node_modules\ts-node\dist\index.js:851:20)
    at Object.<anonymous> (C:\Users\debasis.tripathy\Desktop\files\socioPub\src\index.ts:16:33)
    at m._compile (C:\Users\debasis.tripathy\Desktop\files\socioPub\node_modules\ts-node\dist\index.js:857:29) {
  code: 'ERR_REQUIRE_ESM'
}
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
PS C:\Users\debasis.tripathy\Desktop\files\socioPub> 

Any suggestions kindly let me know Thank you

Upvotes: 0

Views: 167

Answers (0)

Related Questions