{"action":"closed","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/18239","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/18239/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/18239/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/18239/events","html_url":"https://github.com/Microsoft/TypeScript/issues/18239","id":255059467,"number":18239,"title":"BUG: Module resolution not using \"typeRoots\" correctly when used with export =","user":{"login":"kukjevov","id":16702037,"avatar_url":"https://avatars2.githubusercontent.com/u/16702037?v=4","gravatar_id":"","url":"https://api.github.com/users/kukjevov","html_url":"https://github.com/kukjevov","followers_url":"https://api.github.com/users/kukjevov/followers","following_url":"https://api.github.com/users/kukjevov/following{/other_user}","gists_url":"https://api.github.com/users/kukjevov/gists{/gist_id}","starred_url":"https://api.github.com/users/kukjevov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kukjevov/subscriptions","organizations_url":"https://api.github.com/users/kukjevov/orgs","repos_url":"https://api.github.com/users/kukjevov/repos","events_url":"https://api.github.com/users/kukjevov/events{/privacy}","received_events_url":"https://api.github.com/users/kukjevov/received_events","type":"User","site_admin":false},"labels":[{"id":113971558,"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Question","name":"Question","color":"d4c5f9","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-09-04T14:34:18Z","updated_at":"2017-09-22T16:57:51Z","closed_at":"2017-09-22T16:57:51Z","author_association":"NONE","body":"**TypeScript Version:**  2.5.2\r\n\r\n**Code**\r\n\r\nHere is repository with problem.\r\nhttps://github.com/kukjevov/cannot-find-module\r\n\r\nI have following 2 d.ts files\r\n\r\n**`node_modules/@types-my/sample-module/index.d.ts`**\r\n```ts\r\ndeclare let numberRegexp: string;\r\ndeclare class ZipCodeValidator {\r\n    isAcceptable(s: string): void;\r\n}\r\n\r\ndeclare module \"sample-module\"\r\n{\r\n    export = ZipCodeValidator;\r\n}\r\n```\r\n\r\n**`node_modules/@types-my/sample-module2/index.d.ts`**\r\n```ts\r\ndeclare let numberRegexp2: string;\r\ndeclare class ZipCodeValidator2 {\r\n    isAcceptable(s: string): void;\r\n}\r\n\r\nexport = ZipCodeValidator2;\r\n```\r\n\r\nand i have this tsconfig.json\r\n```json\r\n{\r\n    \"compilerOptions\":\r\n    {\r\n        \"target\": \"es5\",\r\n        \"module\": \"commonjs\",\r\n        \"sourceMap\": false,\r\n        \"declaration\": false,\r\n        \"noImplicitAny\": true,\r\n        \"moduleResolution\": \"node\",\r\n        \"strictNullChecks\": true,\r\n        \"traceResolution\": true,\r\n        \"outDir\": \".\",\r\n        \"newLine\": \"LF\",\r\n        \"lib\": \r\n        [\r\n            \"es2016\",\r\n            \"dom\"\r\n        ],\r\n        \"types\": \r\n        [\r\n            \"node\",\r\n            \"sample-module\",\r\n            \"sample-module2\"\r\n        ],\r\n        \"typeRoots\": \r\n        [\r\n            \"node_modules/@types-my\",\r\n            \"node_modules/@types\"\r\n        ]\r\n    },\r\n    \"exclude\": \r\n    [\r\n        \"node_modules\"\r\n    ]\r\n}\r\n```\r\n\r\nThen i have these 3 imports\r\n\r\n```ts\r\nimport zip = require(\"sample-module\");\r\nimport zip3 = require(\"../node_modules/@types-my/sample-module2\");\r\nimport zip2 = require(\"sample-module2\");\r\n```\r\n\r\nFirst two are resolved correctly but last returns error.\r\n>src/index.ts(3,23): error TS2307: Cannot find module 'sample-module2'.\r\n\r\nAccording this https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require it should work also with syntax `export =` and then `import name = require`, but it is not working. \r\n\r\nEven more interesting thing is that if i look at trace resolution\r\n\r\n```\r\n======== Resolving module 'sample-module' from 'D:/Data/git/cannot-find-module/src/index.ts'. ========\r\nExplicitly specified module resolution kind: 'NodeJs'.\r\nLoading module 'sample-module' from 'node_modules' folder, target file type 'TypeScript'.\r\nDirectory 'D:/Data/git/cannot-find-module/src/node_modules' does not exist, skipping all lookups in it.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/sample-module.ts' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/sample-module.tsx' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/sample-module.d.ts' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types/sample-module.d.ts' does not exist.\r\nDirectory 'D:/Data/git/node_modules' does not exist, skipping all lookups in it.\r\nDirectory 'D:/Data/node_modules' does not exist, skipping all lookups in it.\r\nDirectory 'D:/node_modules' does not exist, skipping all lookups in it.\r\nLoading module 'sample-module' from 'node_modules' folder, target file type 'JavaScript'.\r\nDirectory 'D:/Data/git/cannot-find-module/src/node_modules' does not exist, skipping all lookups in it.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/sample-module.js' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/sample-module.jsx' does not exist.\r\nDirectory 'D:/Data/git/node_modules' does not exist, skipping all lookups in it.\r\nDirectory 'D:/Data/node_modules' does not exist, skipping all lookups in it.\r\nDirectory 'D:/node_modules' does not exist, skipping all lookups in it.\r\n======== Module name 'sample-module' was not resolved. ========\r\n======== Resolving module '../node_modules/@types-my/sample-module2' from 'D:/Data/git/cannot-find-module/src/index.ts'. ========\r\nExplicitly specified module resolution kind: 'NodeJs'.\r\nLoading module as file / folder, candidate module location 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2', target file type 'TypeScript'.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2.ts' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2.tsx' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2.d.ts' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2/package.json' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2/index.ts' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2/index.tsx' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2/index.d.ts' exist - use it as a name resolution result.\r\n======== Module name '../node_modules/@types-my/sample-module2' was successfully resolved to 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2/index.d.ts'. ========\r\n======== Resolving module 'sample-module2' from 'D:/Data/git/cannot-find-module/src/index.ts'. ========\r\nExplicitly specified module resolution kind: 'NodeJs'.\r\nLoading module 'sample-module2' from 'node_modules' folder, target file type 'TypeScript'.\r\nDirectory 'D:/Data/git/cannot-find-module/src/node_modules' does not exist, skipping all lookups in it.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/sample-module2.ts' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/sample-module2.tsx' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/sample-module2.d.ts' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types/sample-module2.d.ts' does not exist.\r\nDirectory 'D:/Data/git/node_modules' does not exist, skipping all lookups in it.\r\nDirectory 'D:/Data/node_modules' does not exist, skipping all lookups in it.\r\nDirectory 'D:/node_modules' does not exist, skipping all lookups in it.\r\nLoading module 'sample-module2' from 'node_modules' folder, target file type 'JavaScript'.\r\nDirectory 'D:/Data/git/cannot-find-module/src/node_modules' does not exist, skipping all lookups in it.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/sample-module2.js' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/sample-module2.jsx' does not exist.\r\nDirectory 'D:/Data/git/node_modules' does not exist, skipping all lookups in it.\r\nDirectory 'D:/Data/node_modules' does not exist, skipping all lookups in it.\r\nDirectory 'D:/node_modules' does not exist, skipping all lookups in it.\r\n======== Module name 'sample-module2' was not resolved. ========\r\n======== Resolving type reference directive 'node', containing file 'D:/Data/git/cannot-find-module/__inferred type names__.ts', root directory 'D:/Data/git/cannot-find-module/node_modules/@types-my,D:/Data/git/cannot-find-module/node_modules/@types'. ========\r\nResolving with primary search path 'D:/Data/git/cannot-find-module/node_modules/@types-my, D:/Data/git/cannot-find-module/node_modules/@types'.\r\nFound 'package.json' at 'D:/Data/git/cannot-find-module/node_modules/@types/node/package.json'.\r\n'package.json' does not have a 'typings' field.\r\n'package.json' does not have a 'types' field.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts' exist - use it as a name resolution result.\r\nResolving real path for 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts', result 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\n======== Type reference directive 'node' was successfully resolved to 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts', primary: true. ========\r\n======== Resolving type reference directive 'sample-module', containing file 'D:/Data/git/cannot-find-module/__inferred type names__.ts', root directory 'D:/Data/git/cannot-find-module/node_modules/@types-my,D:/Data/git/cannot-find-module/node_modules/@types'. ========\r\nResolving with primary search path 'D:/Data/git/cannot-find-module/node_modules/@types-my, D:/Data/git/cannot-find-module/node_modules/@types'.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module/package.json' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module/index.d.ts' exist - use it as a name resolution result.\r\nResolving real path for 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module/index.d.ts', result 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module/index.d.ts'.\r\n======== Type reference directive 'sample-module' was successfully resolved to 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module/index.d.ts', primary: true. ========\r\n======== Resolving type reference directive 'sample-module2', containing file 'D:/Data/git/cannot-find-module/__inferred type names__.ts', root directory 'D:/Data/git/cannot-find-module/node_modules/@types-my,D:/Data/git/cannot-find-module/node_modules/@types'. ========\r\nResolving with primary search path 'D:/Data/git/cannot-find-module/node_modules/@types-my, D:/Data/git/cannot-find-module/node_modules/@types'.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2/package.json' does not exist.\r\nFile 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2/index.d.ts' exist - use it as a name resolution result.\r\nResolving real path for 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2/index.d.ts', result 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2/index.d.ts'.\r\n======== Type reference directive 'sample-module2' was successfully resolved to 'D:/Data/git/cannot-find-module/node_modules/@types-my/sample-module2/index.d.ts', primary: true. ========\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'net' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'stream' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'url' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'child_process' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'net' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'stream' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'tls' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'http' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'url' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'stream' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'readline' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'stream' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'stream' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'net' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'stream' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'stream' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'url' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'crypto' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'net' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'stream' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'net' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'events' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'fs' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'net' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'stream' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'tls' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'url' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'http' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nModule 'http' was resolved as locally declared ambient module in file 'D:/Data/git/cannot-find-module/node_modules/@types/node/index.d.ts'.\r\nsrc/index.ts(3,23): error TS2307: Cannot find module 'sample-module2'.\r\n```\r\n\r\ni cant see that even `sample-module` was resolved correctly, but it is. According this log it is not even trying to look at location specified by `typeRoots`.\r\n\r\n**Expected behavior:**\r\nIt should work with both syntax statements. Many of typings downloaded using npm `@types/name`are declared this way and it works, but i cant declare it for my typings this way.\r\n\r\n**Actual behavior:**\r\nNot working, only if module declared as `module \"name\"`.\r\n"}}
{"actor":{"display_login":"mhegazy"}}