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

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay