Repository: TypeScript
Issue: tsc fails when node_modules is symlinked to a target folder not named node_modules
Labels: Bug

<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨

Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common "Bugs" That Aren't Bugs section!

Please help us by doing the following steps before logging an issue:
  * Search: https://github.com/Microsoft/TypeScript/search?type=Issues
  * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ

Please fill in the *entire* template below.
-->

<!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->
**TypeScript Version:**  typescript@3.3.0-dev.20190119

<!-- Search terms you tried before logging this (so others can find this issue more easily) -->
**Search Terms:** symlink node_modules symbolic link

**Code**
Consider a project with the following file.
```ts
import { Command, flags } from "@oclif/command";
...
```

In addition the `node_modules` folder is symlinked to an external folder named `../<path>/node_modules_cli/`.

**Expected behavior:**
The compile to work correctly.

**Actual behavior:**
```
$ yarn tsc
yarn run v1.12.3
$ /nu/skainswo/nuvemfs/nuvemfs-cli/node_modules/.bin/tsc
../../../.links/skainswo/node_modules_cli/@oclif/command/lib/command.d.ts:1:25 - error TS2307: Cannot find module '@oclif/config'.

1 import * as Config from '@oclif/config';
                          ~~~~~~~~~~~~~~~

../../../.links/skainswo/node_modules_cli/@oclif/command/lib/command.d.ts:2:25 - error TS2307: Cannot find module '@oclif/parser'.

2 import * as Parser from '@oclif/parser';
                          ~~~~~~~~~~~~~~~

../../../.links/skainswo/node_modules_cli/@oclif/command/lib/flags.d.ts:1:25 - error TS2307: Cannot find module '@oclif/config'.

1 import { IConfig } from '@oclif/config';
                          ~~~~~~~~~~~~~~~

../../../.links/skainswo/node_modules_cli/@oclif/command/lib/flags.d.ts:2:25 - error TS2307: Cannot find module '@oclif/parser'.

2 import * as Parser from '@oclif/parser';
                          ~~~~~~~~~~~~~~~

../../../.links/skainswo/node_modules_cli/@oclif/command/lib/flags.d.ts:47:34 - error TS2307: Cannot find module '@oclif/parser/lib/flags'.

47 export { boolean, integer } from '@oclif/parser/lib/flags';
                                    ~~~~~~~~~~~~~~~~~~~~~~~~~

../../../.links/skainswo/node_modules_cli/@oclif/command/lib/main.d.ts:1:25 - error TS2307: Cannot find module '@oclif/config'.

1 import * as Config from '@oclif/config';
                          ~~~~~~~~~~~~~~~

../../../.links/skainswo/node_modules_cli/@types/request/index.d.ts:19:27 - error TS2307: Cannot find module 'caseless'.

19 import caseless = require('caseless');
                             ~~~~~~~~~~

../../../.links/skainswo/node_modules_cli/@types/request/index.d.ts:24:27 - error TS2307: Cannot find module 'form-data'.

24 import FormData = require('form-data');
                             ~~~~~~~~~~~

../../../.links/skainswo/node_modules_cli/@types/request/index.d.ts:26:24 - error TS2307: Cannot find module 'tough-cookie'.

26 import tough = require('tough-cookie');
                          ~~~~~~~~~~~~~~


Found 9 errors.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

Which makes no sense since the `node_modules` directory does in fact contain all of the necessary modules.

Moving the destination folder from `../<path>/node_modules_cli/` to `../<path>/node_modules/` fixes everything, and the compile goes through just fine:
```
$ yarn tsc
yarn run v1.12.3
$ /nu/skainswo/nuvemfs/nuvemfs-cli/node_modules/.bin/tsc
✨  Done in 5.54s.
```

I've tested and confirmed this behavior with both relative and absolute symbolic links.

**Playground Link:** n/a

**Related Issues:** <!-- Did you find other bugs that looked similar? -->