{"action":"closed","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10567","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10567/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10567/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10567/events","html_url":"https://github.com/Microsoft/TypeScript/issues/10567","id":173530271,"number":10567,"title":"Cannot find module X...","user":{"login":"MCKRUZ","id":1473014,"avatar_url":"https://avatars.githubusercontent.com/u/1473014?v=3","gravatar_id":"","url":"https://api.github.com/users/MCKRUZ","html_url":"https://github.com/MCKRUZ","followers_url":"https://api.github.com/users/MCKRUZ/followers","following_url":"https://api.github.com/users/MCKRUZ/following{/other_user}","gists_url":"https://api.github.com/users/MCKRUZ/gists{/gist_id}","starred_url":"https://api.github.com/users/MCKRUZ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MCKRUZ/subscriptions","organizations_url":"https://api.github.com/users/MCKRUZ/orgs","repos_url":"https://api.github.com/users/MCKRUZ/repos","events_url":"https://api.github.com/users/MCKRUZ/events{/privacy}","received_events_url":"https://api.github.com/users/MCKRUZ/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2016-08-26T19:51:54Z","updated_at":"2016-08-31T17:36:57Z","closed_at":"2016-08-31T17:36:57Z","body":"<!-- BUGS: Please use this template. -->\r\n<!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\r\n<!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\r\n\r\n**TypeScript Version:**  1.8.0\r\n\r\n**Code**\r\nI have two projects.  One I'm building general gulp tasks in.  One I'm consuming those general gulp tasks.\r\n\r\nProject 1 contains a class called TasksTools that lives in a file called **tasksTools.ts**\r\n```ts\r\nimport { existsSync, lstatSync, readdirSync } from 'fs';\r\nimport * as gulp from 'gulp';\r\nimport * as util from 'gulp-util';\r\nimport * as isstream from 'isstream';\r\nimport { join } from 'path';\r\nimport * as tildify from 'tildify';\r\n\r\nexport class TasksTools {\r\n\tprivate _gulpConfig: any;\r\n\r\n\tconstructor(config: any) {\r\n\t\tthis._gulpConfig = config;\r\n\t}\r\n\r\n\t/**\r\n\t * Loads the tasks within the given path.\r\n\t * @param {string} path - The path to load the tasks from.\r\n\t * @param {any} config\t\t- The configuration file.\r\n\t */\r\n\tpublic loadTasksFromDir(path: string, config: any): void {\r\n\t\tthis._readDir(path, taskname => this.registerTask(taskname, path, config));\r\n\t}\r\n\r\n\t/**\r\n\t * Registers the task by the given taskname and path.\r\n\t * @param {string} taskname - The name of the task.\r\n\t * @param {string} path     - The path of the task.\r\n\t * @param {any} config\t\t- The configuration file.\r\n\t */\r\n\tpublic registerTask(taskname: string, path: string, config: any): void {\r\n\t\tconst TASK = join(path, taskname);\r\n\t\tgulp.task(taskname, (done: any) => {\r\n\t\t\tconst task = require(TASK);\r\n\t\t\tif (task.length > 0) {\r\n\t\t\t\treturn task(config, done);\r\n\t\t\t}\r\n\r\n\t\t\tconst taskReturnedValue = task();\r\n\t\t\tif (isstream(taskReturnedValue)) {\r\n\t\t\t\treturn taskReturnedValue;\r\n\t\t\t}\r\n\r\n\t\t\t// TODO: add promise handling if needed at some point.\r\n\r\n\t\t\tdone();\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Reads the files in the given root directory and executes the given callback per found file.\r\n\t * @param {string}   root - The root directory to read.\r\n\t * @param {function} cb   - The callback to execute per found file.\r\n\t */\r\n\tprivate _readDir(root: string, cb: (taskname: string) => void): void {\r\n\t\tif (!existsSync(root)) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\twalk(root);\r\n\r\n\t\tfunction walk(path: string) {\r\n\t\t\tlet files = readdirSync(path);\r\n\t\t\tfor (let i = 0; i < files.length; i += 1) {\r\n\t\t\t\tlet file = files[i];\r\n\t\t\t\tlet curPath = join(path, file);\r\n\t\t\t\tif (lstatSync(curPath).isFile() && /\\.ts$/.test(file)) {\r\n\t\t\t\t\tlet taskname = file.replace(/\\.ts$/, '');\r\n\t\t\t\t\tcb(taskname);\r\n\t\t\t\t}\r\n\t\t\t\telse if (lstatSync(curPath).isDirectory()) { // recurse\r\n\t\t\t\t\twalk(curPath);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nit also has a definitions file that lives in a file called **index.d.ts**\r\n\r\n```ts\r\ndeclare module \"@mtm/mtm-ng2-gulp-tasks\" {\r\nexport class TasksTools {\r\n\t\tpublic constructor(config: any)\r\n\r\n\t\t/**\r\n\t\t\t* Loads the tasks within the given path.\r\n\t\t\t* @param {string} path - The path to load the tasks from.\r\n\t\t    * @param {any} config\t\t- The configuration file.\r\n\t\t\t*/\r\n\t\tpublic loadTasksFromDir(path: string, config: any): void\r\n\r\n\t\t/**\r\n\t\t\t* Registers the task by the given taskname and path.\r\n\t\t\t* @param {string} taskname - The name of the task.\r\n\t\t\t* @param {string} path     - The path of the task.\r\n\t\t\t* @param {any} config\t\t- The configuration file.\r\n\t\t\t*/\r\n\t\tpublic registerTask(taskname: string, path: string, config: any): void\r\n\t}\r\n}\r\n```\r\n\r\nso I wrap these up and make an NPM library.  Then I import that lib into project 2\r\nHere is my gulp file **gulpfile.ts**\r\n```ts\r\nimport * as gulp from 'gulp';\r\nimport * as config from './gulp.config';\r\nimport * as runSequence from 'run-sequence';\r\nimport * as util from 'gulp-util';\r\n// This line doesn't work\r\nimport { TasksTools } from '@mtm/mtm-ng2-gulp-tasks';\r\n\r\n// If I uncomment this line it works\r\n//import { TasksTools } from './node_modules/@mtm/mtm-ng2-gulp-tasks/utils/momentum.utils';\r\n\r\nlet _gulpConfig = new config.ProjectConfig();\r\nlet _taskTools = new TasksTools(_gulpConfig);\r\n\r\n// Load Default Tasks\r\n_taskTools.loadTasksFromDir(_gulpConfig.MOMENTUM_TASKS_DIR, _gulpConfig);\r\n\r\n// Load Project Tasks\r\n_taskTools.loadTasksFromDir(_gulpConfig.PROJECT_TASKS_DIR, _gulpConfig);\r\n```\r\nNow when I try to run this I get the error\r\n\r\n**Failed to run \"C:\\TFS\\Dev\\Momentum.Torques\\Client\\Gulp\\mtm-ng2-gulp-tasks\\mtm-ng2-gulp-tasks-test\\Gulpfile.js\"...\r\ncmd.exe /c gulp --tasks-simple\r\nmodule.js:442\r\n    throw err;\r\n    ^\r\nError: Cannot find module '@mtm/mtm-ng2-gulp-tasks'**\r\n\r\n\r\n**Expected behavior:**\r\nI expect that this would work\r\n**Actual behavior:** \r\nIt did not work\r\n"}}
{"actor":{"display_login":"mhegazy"}}