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

TypescriptVisual Studio-Code

Typescript Problem Overview


The following is what I want to disable:

[js] File is a CommonJS module; it may be converted to an ES6 module.

I can't find it in settings.
Help appreciated as this is really annoying.

Typescript Solutions


Solution 1 - Typescript

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.

[![][1]][1] [1]: https://i.stack.imgur.com/2AUwp.png

(Image provided by Yusuf Yaşar.)

Solution 2 - Typescript

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
}

Solution 3 - Typescript

Alert! This approach might be too much for VSCode users who love the intelligent coding assistance. Use it as a simple & quick help, together with other linting & testing utilities.


The control of the presence of the said message is located in Settings => Extensions => TypeScript. (TypeScript !!! :P)

As shown in screenshot, I searched in Settings with keyword "validate", then click TypeScript. It's the first item.

enter image description here

Solution 4 - Typescript

For anyone using Neovim with Native LSP and nvim-lspconfig for setting up your language servers, you can disable suggestions by adding this somewhere in your tsserver setup:

require('lspconfig').tsserver.setup({
    init_options = {
        preferences = {
            disableSuggestions = true,
        },
    },
})

You can also use the nvim-lsp-ts-utils plugin to filter out this specific diagnostic message while keeping suggestions enabled by adding this somewhere in your tsserver setup:

require('lspconfig').tsserver.setup({
    on_attach = function(client, bufnr)
        require('nvim-lsp-ts-utils').setup({
            filter_out_diagnostics_by_code = { 80001 },
        })
        require('nvim-lsp-ts-utils').setup_client(client)
    end,
})

Solution 5 - Typescript

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.

Solution 6 - Typescript

If you are getting this error in Next js, try the code below.

  1. Next.js includes the "next/babel" preset to your app, which includes everything needed to compile React applications and server-side code.

  2. Open your .eslintrc.json

    { "extends" : "next/babel" }
    
  3. But if you want to extend the default Babel configs, it's also possible. https://nextjs.org/docs/advanced-features/customizing-babel-config

Solution 7 - Typescript

Maybe you don't have function(request, response), try it. It works for me

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSunburntRock89View Question on Stackoverflow
Solution 1 - TypescriptHSirView Answer on Stackoverflow
Solution 2 - Typescripticc97View Answer on Stackoverflow
Solution 3 - TypescriptthemefieldView Answer on Stackoverflow
Solution 4 - TypescriptCyhyraethView Answer on Stackoverflow
Solution 5 - TypescriptweakishView Answer on Stackoverflow
Solution 6 - TypescriptCelal YıldırımView Answer on Stackoverflow
Solution 7 - TypescriptNguyễn Thị Minh NgọcView Answer on Stackoverflow