DEV Community

Cover image for No jsconfig.json, no fun
Andreas Riedmüller
Andreas Riedmüller

Posted on • Edited on

8

No jsconfig.json, no fun

I switched to VS Code recently and had an issue that really bogged me: Often Functions/Components did not appear in the list of IntelliSense autocomplete suggestions. But after opening the file containing the Function it suddenly got added to the list.

Suggestion not showing up
No IntelliSense suggestion for ExampleCard

Suggestion showing up
Suggestion shows up after opening ExampleCard.js

jsconfig.json to the rescue

To be honest, it took me some time to find out what was going on.

Visual Studio Code's JavaScript support can run in two different modes: File Scope and Explicit Project.

And this was the cause of my issue: Some of my projects ran in File Scope mode and JavaScript files were treated as independent units by VS Code.

To solve my issue I just had to enabled Explicit Project mode by creating a jsconfig.json in my project.

You can more about the jsconfig.json file and and the two modes in the official documentation.

Image description
Everything shows up now 🥳

So all good now and lesson learned: When working with Visual Studio Code always make sure you have a jsconfig.json set up when working in a Javascript project.

Examples for a jsconfig.json

Here is the jsconfig.json I use for a Gatsby project:



{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "Node",
    "target": "ES2020",
    "jsx": "react",
    "lib": [
      "esnext",
      "dom"
    ]
  },
  "include": [
    "./src/**/*",
    "./gatsby-node.ts",
    "./gatsby-config.ts",
    "./plugins/**/*"
  ]
}


Enter fullscreen mode Exit fullscreen mode

And this is a more general version for React web projects that includes all files except files in node_modules:



{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "Node",
    "target": "ES2020",
    "jsx": "react",
    "lib": [
      "esnext",
      "dom"
    ]
  },
  "exclude": [
    "node_modules",
    "**/node_modules/*"
  ]
}


Enter fullscreen mode Exit fullscreen mode

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay