0

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?

D.L
  • 4,339
  • 5
  • 22
  • 45
  • show a [mre]. That includes a minimal package.json and output of `npm list mathjs` – starball Apr 12 '23 at 20:43
  • I don't have this issue. You probably need to provide more info to make this reproducible. Ex. what is in your hello_world.js file. What versions of all your relevant tools do you have installed, etc. Out of curiosity, what happens if you just restart VS Code? – starball Apr 12 '23 at 20:56
  • ?? why does your JS file have _Python_ in it? "_`print('hello world')`_" Why are you testing your repro in a _previous_ project? You should be doing it in a fresh one. – starball Apr 12 '23 at 22:39
  • why are you installing `@types/mathjs` when [`mathjs` already publishes its types](https://www.npmjs.com/package/mathjs)? (see the blue "TS" icon) – starball Apr 12 '23 at 22:42
  • @user, the `package.json` was automatically updated, presumably when i ran the `npm install`... should i delete this line `"@types/mathjs": "^9.4.2",` ? ..it seems that deleting this line has no particular effect. – D.L Apr 12 '23 at 22:47
  • For above stated reasons, I don't see why you would need that dependency. Yes, delete it and then run `npm install` to update `node_modules/`. Try restarting VS Code for good measure too after you do that. I'm also curious about what happens if you remove the exclusion of `node_modules` from your jsconfig.json file. – starball Apr 12 '23 at 23:12
  • deleted `"@types/mathjs": "^9.4.2"`, run `npm install`, also removed `node_modules` from the `jsconfig.json` file..... no effect. same error persists. – D.L Apr 13 '23 at 14:47

1 Answers1

-1

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.

D.L
  • 4,339
  • 5
  • 22
  • 45