{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/28432","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/28432/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/28432/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/28432/events","html_url":"https://github.com/Microsoft/TypeScript/issues/28432","id":379130383,"node_id":"MDU6SXNzdWUzNzkxMzAzODM=","number":28432,"title":"TSC fails to emit required files when run below node_modules","user":{"login":"yofreke","id":536581,"node_id":"MDQ6VXNlcjUzNjU4MQ==","avatar_url":"https://avatars3.githubusercontent.com/u/536581?v=4","gravatar_id":"","url":"https://api.github.com/users/yofreke","html_url":"https://github.com/yofreke","followers_url":"https://api.github.com/users/yofreke/followers","following_url":"https://api.github.com/users/yofreke/following{/other_user}","gists_url":"https://api.github.com/users/yofreke/gists{/gist_id}","starred_url":"https://api.github.com/users/yofreke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yofreke/subscriptions","organizations_url":"https://api.github.com/users/yofreke/orgs","repos_url":"https://api.github.com/users/yofreke/repos","events_url":"https://api.github.com/users/yofreke/events{/privacy}","received_events_url":"https://api.github.com/users/yofreke/received_events","type":"User","site_admin":false},"labels":[{"id":371615203,"node_id":"MDU6TGFiZWwzNzE2MTUyMDM=","url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Working%20as%20Intended","name":"Working as Intended","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-11-09T11:44:08Z","updated_at":"2018-11-09T21:18:09Z","closed_at":null,"author_association":"NONE","body":"<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf 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!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n  * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n  * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n<!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:**  3.2.0-dev.20181107\r\n\r\n<!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** node_modules\r\n\r\n**Code**\r\n\r\n\r\n`/tmp/node_modules/tsc-test/tsconfig.json`\r\n```json\r\n{\r\n  \"compilerOptions\": {\r\n    \"outDir\": \"dist\"\r\n  },\r\n  \"files\": [\r\n    \"src/index.ts\"\r\n  ]\r\n}\r\n```\r\n\r\n`/tmp/node_modules/tsc-test/src/index.ts`\r\n```ts\r\nimport { A } from './A';\r\n\r\nexport const main = () => {\r\n  console.log('A=', A);\r\n};\r\n```\r\n\r\n`/tmp/node_modules/tsc-test/src/A.ts`\r\n```ts\r\nexport const A = 'A';\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nOutput files:\r\n\r\n- `/tmp/node_modules/tsc-test/dist/index.js`\r\n- `/tmp/node_modules/tsc-test/dist/A.js`\r\n\r\n**Actual behavior:**\r\n\r\nOutput files:\r\n\r\n`/tmp/node_modules/tsc-test/dist/index.js`\r\n```js\r\n\"use strict\";\r\nexports.__esModule = true;\r\nvar A_1 = require(\"./A\");\r\nexports.main = function () {\r\n    console.log('A=', A_1.A);\r\n};\r\n```\r\n\r\n_No `A.js` is output_\r\n\r\n**Notes:**\r\n\r\nI wanted to build a typescript project as part of an npm postinstall script, to enable installation from npm or from git.  In the case of installation from npmjs, `dist/` will already exist.  In the case of installation from git, `dist/` will be missing and build will be run.\r\n\r\nAfter setting this up, I noticed that only files listed in my tsconfig `files` list were being emitted when installing from git.  I looked around for tsconfig or tsc options that may change this behavior, but realized it probably had to do with `'node_modules'` being in the path.\r\n\r\nI debugged the issue by modifying the built `tsc.js`.  In my case, the problematic code is in `nodeModuleNameResolverWorker/tryResolve`, specifically [here](https://github.com/Microsoft/TypeScript/blob/b534fb4849eca0a792199fb6c0cb8849fece1cfd/src/compiler/moduleNameResolver.ts#L918:L921):\r\n```ts\r\nconst { path: candidate, parts } = normalizePathAndParts(combinePaths(containingDirectory, moduleName));\r\nconst resolved = nodeLoadModuleByRelativeName(extensions, candidate, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true);\r\n// Treat explicit \"node_modules\" import as an external library import.\r\nreturn resolved && toSearchResult({ resolved, isExternalLibraryImport: contains(parts, \"node_modules\") });\r\n```\r\n\r\nThe call to `contains(parts, \"node_modules\")` should likely consider the project root directory, and ignore `\"node_modules\"` in the path parts above the root."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/437498123","html_url":"https://github.com/Microsoft/TypeScript/issues/28432#issuecomment-437498123","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/28432","id":437498123,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNzQ5ODEyMw==","user":{"login":"weswigham","id":2932786,"node_id":"MDQ6VXNlcjI5MzI3ODY=","avatar_url":"https://avatars3.githubusercontent.com/u/2932786?v=4","gravatar_id":"","url":"https://api.github.com/users/weswigham","html_url":"https://github.com/weswigham","followers_url":"https://api.github.com/users/weswigham/followers","following_url":"https://api.github.com/users/weswigham/following{/other_user}","gists_url":"https://api.github.com/users/weswigham/gists{/gist_id}","starred_url":"https://api.github.com/users/weswigham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weswigham/subscriptions","organizations_url":"https://api.github.com/users/weswigham/orgs","repos_url":"https://api.github.com/users/weswigham/repos","events_url":"https://api.github.com/users/weswigham/events{/privacy}","received_events_url":"https://api.github.com/users/weswigham/received_events","type":"User","site_admin":false},"created_at":"2018-11-09T21:18:09Z","updated_at":"2018-11-09T21:18:09Z","author_association":"MEMBER","body":"Right, what I'm getting at is that if the project root is `/a/b/node_modules/c/d`, anything beneath `/a/b/node_modules/c/d` should be built. `/a/b/node_modules/c` shouldn't be, `/a/b/node_modules/c/d/node_modules/e` shouldn't be."}}
{"actor":{"display_login":"weswigham"}}