microsoft / microsoft/TypeScript

Module.exports = {} not recognized by IntelliSense

Open
#31,928 3 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript version: 3.5.1

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 in other scripts.

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

showTe...;  // <- no import suggestion provided

Project structure:

./lib.js
./myCode.js

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the provided lib.js and myCode.js files, using module.exports = {} and checking import suggestions for showText in myCode.js. Investigate the IntelliSense behavior for this CommonJS pattern; done means the suggestion appears without converting the export to ES6 syntax or changing its property format.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.