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.)
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
}
how can i fix --> File is a CommonJS module; it may be converted to an ES6 module
Error "File is a commonJS module; it may be converted to an ES6 module. ts(80001)"
Trouble using require(); Needing to convert JS file to ES module
Conversion to ES Module should not change whole-module import to named imports
Use the .cjs file extension instead of .js to note that the file will remain a CommonJS module instead of an ES6 module (.mjs). You will still get other code suggestionActions this way.
It's hinting to convert the code to support ES module standards. ES module is a standard module format that both browsers and the backend node environment support.
"File is a CommonJS module; it may be converted to an ES module"
This is not error, just a warning. You can still use commonjs and require() (provided that the package supports CommonJs). It will still work. Preferrably, you can change your extension name to .cjs to mark your file as a commonjs file and the warning should disappear
The bigger context here is that Typescript/JavaScript is trying to encourage people to use the new ES6 module system, with import and export instead of the old CommonJS with require() and exports.
You can use the new ES6 module import/export syntax, by adding to the package.json this property: "type": "module" and then instead of require() you use import ... from.
Many modern packages have changed to support ES6 modules, so it is recommended that you also use ES6 module syntax. But again, you can still use require() if you prefer if the package you import supports commonjs
Similar question: Error "File is a commonJS module; it may be converted to an ES6 module. ts(80001)"
You must notice that the require() is a CommonJS directive that it is requesting a ESModule like it was a CommonJS. EDIT: It will always throw an error message because it's not supported.
Of course, you still must take in consideration this other answer by Bao Huynh Lam in the list here. It's pretty useful information.
You can dynamically import() any ESModule inside your CommonJS file.
Here's an example:
some-file.cjs (which is CommonJS)
new Promise
(
( resolve, reject ) =>
{
import('./module.mjs').then
(
result => resolve(result),
reason => reject(reason),
)
}
)
.then
(
moduleImported => console.log('Module imported dynamically:', moduleImported),
moduleRejected => console.log('Failed to retrieve module:', moduleRejected),
);
module.mjs (which is ESModule)
export default { moduleFile: import.meta.url };