首页 > 解决方案 > VSCode Intellisense not fully working with ES6 imports?

问题描述

I am having trouble getting Intellisense to work completely with ES6 imports.

Doing the following from /index.js gets Intellisense to work correctly:

working example

However, doing the following from /index.js breaks Intellisense:

broken example

The directory structure is:

| modules
|-- cars.js
|-- index.js
| index.js
| jsconfig.json

The contents of each file are:

modules/cars.js

export default {
  audi: 'R8',
  dodge: 'Durango',
};

modules/index.js

import cars from './cars';

export default {
  cars,
};

jsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs"
  },
  "exclude": [
    "node_modules"
  ]
}

标签: ecmascript-6visual-studio-codeintellisense

解决方案


Cars isn't a named export of modules/index.js. The default export of modules/index.js is an object, which then contains cars. To get what you want, make the contents of modules/index.js this:

export { default as cars } from './cars';

推荐阅读