Module.exports = {} not recognized by IntelliSense

Viewed 1068

The CommonJS construct module.exports = {} does not provide import suggestions in JS files via VSCode IntelliSense.

IntelliSense provides a TS error handle on the module.exports = {} construct:

File is a CommonJS module; it may be converted to an ES6 module.ts(80001)

Pressing the Quick Fix option converts the exports to ES6 format. After this, IntelliSense import suggestions work.

What also works is formatting the export as follows:

module.exports.showText = showtext;

My files are:

lib.js

function showText() {
  console.log('Text');
}

module.exports = {
  showText: showText,
}

myCode.js

showText();  // <- no import suggestion provided

I would like to get the IntelliSense import suggestion without change of the module.exports = {} construct (I do not have the authorization to do this for the entire project code base).

I am not using a jsconfig.json file.

0 Answers
Related