How do I disable: [js] File is a CommonJS module; it may be converted to an ES6 module

This is a new feature added in Visual Studio Code called "Suggestion Code Actions". "Suggestion Code Actions" are enabled by default in JavaScript and TypeScript.

You can disable them by setting: "typescript.suggestionActions.enabled": false or "javascript.suggestionActions.enabled": false in your user/workspace settings. The documentation can be found here.

(Image provided by Yusuf Yaşar.)


For anyone using Vim with coc.nvim, you can make the same change by adding the same in the :CocConfig object:

"javascript.suggestionActions.enabled": false

If you haven't added any settings to :CocConfig before, then you need to make sure the above setting is wrapped in a JSON object:

{
    "javascript.suggestionActions.enabled": false
}

Actually this annoying suggestion comes from TypeScript.

Thus, to turn off this suggestion, you can modify the source code of TypeScript, compile it, then tell vscode to use your fork of TypeScript.

As a quick and dirty hack, just remove the logic related to ts.Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module, then compile the project following the instructions on TypeScript's README.

The compilation will fail because removing the related logic causes some functions become unused, then you just remove those unused function definitions and recompile the project (gulp clean && gulp local).

After you successfully compile your fork of TypeScript, then change your user settings.json to point to your vscode fork:

"typescript.tsdk": "/path/to/your/fork/of/TypeScript/built/local",

Done.

Restart your vscode, and the annoying suggestion has gone.

You can check this commit to see which source files of TypeScript need to be modify.

Warn: the modification is quick and dirty, use them at your own risk. If you find anything wrong, you can just remove the tsdk configuration, to switch back to vscode's built-in TypeScript.