vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Intellisense stops working after adding jsconfig file

Open lucasgodshalk opened this issue 10 years ago • 6 comments

  • VSCode Version: 1.0.0
  • OS Version: Windows 10

It seems after I have Code generate a jsconfig file, the intellisense for my imported es6 module seems to quit working.

Initially I have just two files in a folder: script1.js:

export const MyVar = {
    a: 5,
    b: "hello"
};

script2.js:

import { MyVar } from "./script1.js";

Code gives nice completion while typing in script2.js, telling me MyVar has an a and b property.

I then generate the default jsconfig file. At this point, the code completion for MyVar in script2.js stops working, as well as any other features that require cross-file knowledge (Go to Definition for instance). Code completion also stops working for any npm modules I have installed, imported using es6 module syntax.

Any variables declared in script2.js continue to have intellisense.

Here's the jsonconfig file in case it helps (again, it's just the default):

{
    "compilerOptions": {
        "target": "es6"
    },
    "exclude": [
        "node_modules",
        "bower_components",
        "jspm_packages",
        "tmp",
        "temp"
    ]
}

lucasgodshalk avatar Apr 21 '16 14:04 lucasgodshalk

@jrieken I was able to reproduce on latest alpha. Use the new trace options shows the following tsserver communication:

Sending request: completions (80). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/5611/script2.js",
    "line": 3,
    "offset": 7
}

Response received: completions (80). Request took 8 ms. Success: true 
Result: [
    {
        "name": "MyVar",
        "kind": "warning",
        "kindModifiers": "",
        "sortText": "1"
    }
]

Adding the following line to jsonfig.json makes everything work again:

        "module": "commonjs"

Should we consider adding this line. Or is this a deeper TS issue

dbaeumer avatar Apr 21 '16 19:04 dbaeumer

That fixed it for me on 1.0 as well.

lucasgodshalk avatar Apr 21 '16 20:04 lucasgodshalk

I think we left that out in the assumption that TypeScript uses commonjs as default anyways. @egamma might know more

jrieken avatar Apr 22 '16 07:04 jrieken

Yes this was also my assumption, but I've found a mail message from March about the module attribute in JS.

From @billti about the module attribute:

This is more a down-level compile setting. It specifies what the emitted module format will be. It defaults to CommonJS, unless you are targeting ES2015 emit.

We are targetting es2015, so it looks like we should add it.

egamma avatar Apr 22 '16 14:04 egamma

verified that the generated jsconfig.json now includes module: commonjs.

egamma avatar Apr 28 '16 15:04 egamma

I'm a react developer and I have run into the same issue today.

I'm running vs code 1.4.0 (latest I believe) on a windows 7 machine. after I created jsconfig.json, the react extension (Reactjs code snippets to be specific) stops working. google direct me to this page and I have to delete that jsconfig.json file and re-open my folder. then that code snippet extension start working.

I think the issue might be:

  1. mis-configuration in jsconfig.json I'm using the default one generated by vs code
{
    // See https://go.microsoft.com/fwlink/?LinkId=759670
    // for the documentation about the jsconfig.json format
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "allowSyntheticDefaultImports": true
    },
    "exclude": [
        "node_modules",
        "bower_components",
        "jspm_packages",
        "tmp",
        "temp"
    ]
}

do I need to change anything to make that reactjs code snippets work again?

  1. extension provider's issue
  2. vs code's issue (or limitation)

any suggestion appreciated

bchenSyd avatar Sep 01 '16 09:09 bchenSyd