Cannot find type definition file for 'mathjs'

98 Views Asked by At

I have a new install of VSCode on Windows 11.

I open a previous project and create a hello_world.js file. The contents of the hello world are simply:

console.log('hello world');

In my jsconfig.json I have this error message:

Cannot find type definition file for 'mathjs'.
  The file is in the program because:
    Entry point for implicit type library 'mathjs'

JSON schema for a JavaScript project using TypeScript tooling 

I have mathjs in the node_modules folder.

This is the contents of the jsconfig.json file:

{
    "compilerOptions": {
        "module": "ESNext",
        "moduleResolution": "Node",
        "target": "ES2020",
        "jsx": "react",
        "strictNullChecks": true,
        "strictFunctionTypes": true
    },
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ]
}

I also include the package.json file:

{
  "dependencies": {
    "@types/mathjs": "^9.4.2",
    "mathjs": "^11.8.0",
    "type": "module"
  }
}

I have seen this answer and tried the solutions with no success: Seeing unknown typescript error in JSConfig.json file

So I am totally stuck.
What does this mean and how can I safely remove the error?

1

There are 1 best solutions below

0
D.L On BEST ANSWER

It occurred to me to just remove the filename of the jsconfig.json file (for the reasons set out below).

I did stumbling upon this and try all the options which did not work, but lead to the above thought: "internal/modules/cjs/loader.js:582 throw err"

So what i did was to rename this file from jsconfig.json to __jsconfig.json and the error was removed.

Ultimately (although i do not know the exact reason), vscode reads this file as per the docs (https://code.visualstudio.com/docs/languages/jsconfig).

For good measure i also changed package.json to __package.json.