{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/vscode/issues/6586","repository_url":"https://api.github.com/repos/Microsoft/vscode","labels_url":"https://api.github.com/repos/Microsoft/vscode/issues/6586/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/vscode/issues/6586/comments","events_url":"https://api.github.com/repos/Microsoft/vscode/issues/6586/events","html_url":"https://github.com/Microsoft/vscode/issues/6586","id":156023215,"number":6586,"title":"Unable to run extension unit tests via gulp (cannot find module 'vscode')","user":{"login":"jeffyoung","id":2796865,"avatar_url":"https://avatars.githubusercontent.com/u/2796865?v=3","gravatar_id":"","url":"https://api.github.com/users/jeffyoung","html_url":"https://github.com/jeffyoung","followers_url":"https://api.github.com/users/jeffyoung/followers","following_url":"https://api.github.com/users/jeffyoung/following{/other_user}","gists_url":"https://api.github.com/users/jeffyoung/gists{/gist_id}","starred_url":"https://api.github.com/users/jeffyoung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeffyoung/subscriptions","organizations_url":"https://api.github.com/users/jeffyoung/orgs","repos_url":"https://api.github.com/users/jeffyoung/repos","events_url":"https://api.github.com/users/jeffyoung/events{/privacy}","received_events_url":"https://api.github.com/users/jeffyoung/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/vscode/labels/needs%20more%20info","name":"needs more info","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-20T18:26:32Z","updated_at":"2016-05-23T14:17:23Z","closed_at":null,"body":"- VSCode Version: 1.1.1\r\n- OS Version: Windows 10\r\n\r\nI'm developing an extension for VS Code and writing unit tests against my objects used by that extension.  Those tests run successfully from within VS Code.  However, I also run them as part of my CI build and I do that via gulp.  I have a gulp task that uses \"gulp mocha\" to run the tests.  Those tests run successfully via gulp until I bring in a class that, anywhere in its transitive closure of module references, pulls in 'vscode'.\r\n\r\nMy gulp output is below:\r\n\r\n    [14:00:48] Starting 'test'...\r\n    [14:00:48] { [Error: Cannot find module 'vscode']\r\n      code: 'MODULE_NOT_FOUND',\r\n      name: 'Error',\r\n      message: 'Cannot find module \\'vscode\\'',\r\n      stack: 'Error: Cannot find module \\'vscode\\'\\n\r\n    at Function.Module._resolveFilename     (module.js:325:15)\\n\r\n    at Function.Module._load (module.js:276:25)\\n\r\n    at Module.require     (module.js:353:17)\\n\r\n    at require (internal/module.js:12:17)\\n\r\n    at Object.<anonymous> (C:\\\\vsts-    vscode.repro.0\\\\out\\\\src\\\\myobject.js:2:18)\\n\r\n    at Module._compile (module.js:397:26)\\n\r\n    at     Object.Module._extensions..js (module.js:404:10)\\n\r\n    at Module.load (module.js:343:32)\\n\r\n    at     Function.Module._load (module.js:300:12)\\n\r\n    at Module.require (module.js:353:17)',\r\n      showStack: true,\r\n      showProperties: true,\r\n      plugin: 'gulp-mocha' }\r\n    [14:00:48] 'test' errored after 45 ms\r\n    [14:00:48] Error in plugin 'gulp-mocha'\r\n    Message:\r\n        Cannot find module 'vscode'\r\n    Details:\r\n        code: MODULE_NOT_FOUND\r\n    Stack:\r\n    Error: Cannot find module 'vscode'\r\n        at Function.Module._resolveFilename (module.js:325:15)\r\n        at Function.Module._load (module.js:276:25)\r\n        at Module.require (module.js:353:17)\r\n        at require (internal/module.js:12:17)\r\n        at Object.<anonymous> (C:\\vsts-vscode.repro.0\\out\\src\\myobject.js:2:18)\r\n        at Module._compile (module.js:397:26)\r\n        at Object.Module._extensions..js (module.js:404:10)\r\n        at Module.load (module.js:343:32)\r\n        at Function.Module._load (module.js:300:12)\r\n        at Module.require (module.js:353:17)\r\n\r\nIn the call stack, there's a reference to out\\src\\myobject.js:2:18.  At that location is this statement:\r\n\r\n    const vscode_1 = require(\"vscode\");\r\n\r\nIn my typescript source, that is:\r\n\r\n    import { workspace } from \"vscode\";\r\n\r\nIf I remove the code that uses workspace, the tests go back to running successfully.\r\n\r\nAfter going through the documentation regarding [node.js module resolution] (https://nodejs.org/api/modules.html#modules_all_together), I can understand why I get MODULE_NOT_FOUND.  Since \"vscode\" isn't a core module and isn't a relative reference (\".\", \"/\", \"../\"), node will look for the package.json file.  Assuming it finds it (procmon tells me it does), it looks for a \"main\" field.  I'm guessing, at this point, it doesn't find the \"main\" field and fails the resolution.\r\n\r\nPresumably, when running the tests in VS Code, the resolution also includes [locating the typings file] (http://www.typescriptlang.org/docs/handbook/module-resolution.html) and is thus successful.\r\n\r\nWhat I can't figure out is what I might do to resolve the reference to \"vscode\" when I run tests via gulp.\r\n\r\nAny thoughts?\r\n\r\n**myobject.ts**\r\n\r\n    import { workspace } from \"vscode\";   \r\n    export class MyObject {\r\n        constructor() {\r\n            let configuration = workspace.getConfiguration();\r\n        }\r\n    }\r\n\r\n**myobject.test.ts**\r\n\r\n    import { MyObject } from \"../src/myobject\";\r\n    var assert = require(\"chai\").assert;    \r\n    describe(\"MyObject\", function() {\r\n        it(\"should verify MyObject\", function() {\r\n            new MyObject();\r\n        });\r\n    });\r\n\r\n**package.json** (scripts and dependencies)\r\n\r\n    \"scripts\": {\r\n      \"vscode:prepublish\": \"node ./node_modules/vscode/bin/compile\",\r\n      \"compile\": \"node ./node_modules/vscode/bin/compile -watch -p ./\",\r\n      \"postinstall\": \"node ./node_modules/vscode/bin/install\"\r\n    },\r\n    \"devDependencies\": {\r\n      \"chai\": \"^3.4.1\",\r\n      \"gulp\": \"^3.9.0\",\r\n      \"gulp-mocha\": \"^2.2.0\",\r\n      \"gulp-tslint\": \"^3.2.0\",\r\n      \"gulp-util\": \"^3.0.7\",\r\n      \"should\": \"^8.1.1\",\r\n      \"typescript\": \"^1.7.5\",\r\n      \"vscode\": \"^0.11.x\"\r\n    },"},"comment":{"url":"https://api.github.com/repos/Microsoft/vscode/issues/comments/220993078","html_url":"https://github.com/Microsoft/vscode/issues/6586#issuecomment-220993078","issue_url":"https://api.github.com/repos/Microsoft/vscode/issues/6586","id":220993078,"user":{"login":"jeffyoung","id":2796865,"avatar_url":"https://avatars.githubusercontent.com/u/2796865?v=3","gravatar_id":"","url":"https://api.github.com/users/jeffyoung","html_url":"https://github.com/jeffyoung","followers_url":"https://api.github.com/users/jeffyoung/followers","following_url":"https://api.github.com/users/jeffyoung/following{/other_user}","gists_url":"https://api.github.com/users/jeffyoung/gists{/gist_id}","starred_url":"https://api.github.com/users/jeffyoung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeffyoung/subscriptions","organizations_url":"https://api.github.com/users/jeffyoung/orgs","repos_url":"https://api.github.com/users/jeffyoung/repos","events_url":"https://api.github.com/users/jeffyoung/events{/privacy}","received_events_url":"https://api.github.com/users/jeffyoung/received_events","type":"User","site_admin":false},"created_at":"2016-05-23T14:17:23Z","updated_at":"2016-05-23T14:17:23Z","body":"Hi @weinand.  I've made sure that step gets run so the proper version of vscode gets installed.\r\n\r\n    > node ./node_modules/vscode/bin/install\r\n    Detected VS Code engine version: ^0.10.7\r\n    Found minimal version that qualifies engine range: 0.10.8\r\n    Fetching vscode.d.ts from:     https://raw.githubusercontent.com/Microsoft/vscode/0.10.8/src/vs/vscode.d.ts\r\n    vscode.d.ts successfully installed!\r\n\r\nI can provide a small-ish repro that will run successfully within VS Code but a minimal gulpfile.js will result in the missing module error (it's about an 11KB zip file).\r\n\r\n\r\n"}}
{"actor":{"display_login":"jeffyoung"}}