Description
From @mattflix on April 29, 2016 21:46
- VSCode Version: 1.0.0
- OS Version: Mac OS 10.11.3
Steps to Reproduce:
- Create the following project structure.
- Open the root folder in VS Code.
- Observe errors and poor Intellisense in ./src/entry.js.
It appears that the "Node module resolution" support in VS Code is incomplete, and only understands two variants:
- how to resolve a single file as a module (e.g., ./src/node_modules/foo.ts),
- how to resolve a folder as a module that contains an "index" file (e.g., ./src/node_modules/bar/index.ts).
It doesn't understand the third variant:
- how to resolve a folder as a module that contains a "package" file (e.g., ./src/node_modules/baz/package.json pointing to ./src/node_modules/baz/main.ts).
All three of these variants (in any mixture) are vital to proper support for "Node module resolution" in modular Node project structures.
Also, none of these variants work when the file extensions are .js instead of .ts (even when using a jsconfig.json file or allowJs=true). This is terrible, and makes VS Code useless for navigating many existing Javascript projects. The fact than any of the variants work for .ts files is great, but they should definitely work for .js files!
./tsconfig.json
{
"compilerOptions": {
"module": "es6",
"moduleResolution": "node"
}
}
./src/entry.ts
import foo from 'foo'; // OK
import bar from 'bar'; // OK
import baz from 'baz'; // [ts] Cannot find module 'baz'.
foo.foo(); // has Intellisense
bar.bar(); // has Intellisense
baz.baz(); // does not have Intellisense
./src/node_modules/foo.ts
export function foo(x: string) {}
./src/node_modules/bar/index.ts
export function bar(y: number) {}
./src/node_modules/baz/package.json
{
"name": "baz",
"version": "1.0.0",
"main": "./main.ts"
}
./src/node_modules/baz/main.ts
export function baz(z: boolean) {}
Copied from original issue: microsoft/vscode#6001