Skip to content

Intellisense not working with commonjs package #29034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leepowelldev opened this issue Dec 1, 2018 · 2 comments
Closed

Intellisense not working with commonjs package #29034

leepowelldev opened this issue Dec 1, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@leepowelldev
Copy link

I am attempting to consume a NPM module that has been built with babel into two build directories - one for es modules and the other for commonjs modules. The package.json 'main' property for the module points to the commonjs version, and it also has an additional 'module' property that points to the es module version.

"main": "./cjs/index.js",
"module": "./esm/index.js"

When I import the module into my project, Intellisense automatically chooses the commonjs version of the build i.e.

import { Button } from 'theirModule'

In this case, the index.js file in the root of the commonjs build re-exports a number of other exports from other files like so:

Object.defineProperty(exports, "__esModule", { value: true });

var _Button = require("./Button");

Obejct.keys(_Button).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  Object.defineProperty(exports, key, {
    // ....
  })
});

For some reason Intellisense doesn't seem to work when I import like this... however if I point to the es module version it works as expected:

import { Button } from 'theirModule/esm'; // picks up index.js file

The only way I can make it work with the commonjs version is to import directly from the re-exported file:

import { Button } from 'theirModule/cjs/Button';

Am I doing something wrong? I have tried adding a jsconfig.json file but all the settings I have tried make no difference.

@vscodebot vscodebot bot assigned mjbvz Dec 1, 2018
@mjbvz mjbvz transferred this issue from microsoft/vscode Dec 14, 2018
@mjbvz
Copy link
Contributor

mjbvz commented Dec 14, 2018

Yes, I don't think our IntelliSense will be able to make sense of the javascript in /cjs/index.js.

Moving upstream to see if TypeScript should use module from the package.json. Possible already tracked here: #21423

@mjbvz mjbvz removed their assignment Dec 14, 2018
@weswigham
Copy link
Member

Yep, duplicates #21423

@weswigham weswigham added the Duplicate An existing issue was already created label Dec 17, 2018
@mjbvz mjbvz closed this as completed Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants