Problem:
I created a Visual Studio Team Services task in Node and when I execute on a Windows based agent I get the following error:
2016-01-17T08:10:05.1963238Z ##[error]module.js:338
2016-01-17T08:10:05.1963238Z ##[error] throw err;
2016-01-17T08:10:05.1963238Z ##[error] ^
2016-01-17T08:10:05.1963238Z ##[error]Error: Cannot find module 'q'
2016-01-17T08:10:05.1963238Z ##[error] at Function.Module._resolveFilename (module.js:336:15)
2016-01-17T08:10:05.1963238Z ##[error] at Function.Module._load (module.js:278:25)
2016-01-17T08:10:05.1963238Z ##[error] at Module.require (module.js:365:17)
2016-01-17T08:10:05.1963238Z ##[error] at require (module.js:384:17)
2016-01-17T08:10:05.1963238Z ##[error] at Object.<anonymous> (C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\default\tasks\DockerBuild\0.3.57\dockerbuild.js:8:9)
2016-01-17T08:10:05.1963238Z ##[error] at Module._compile (module.js:460:26)
2016-01-17T08:10:05.1963238Z ##[error] at Object.Module._extensions..js (module.js:478:10)
2016-01-17T08:10:05.1963238Z ##[error] at Module.load (module.js:355:32)
2016-01-17T08:10:05.1963238Z ##[error] at Function.Module._load (module.js:310:12)
2016-01-17T08:10:05.1963238Z ##[error] at Module.require (module.js:365:17)
Solution:
Statically link the q module in your node_modules folder.
Explanation:
When you publish a task to VSTS using TFX everything in the task path is uploaded with the task. Therefore, make sure the q module is included in that upload. I create a batch script that copies the desired files to a temp directory then run the upload command from TFX from that folder. That way I do not upload my entire node_modules folder. It is also recommended that statically link vso-task-lib. Below is an example of my folder structure. The tools folder contains files I need access to for my task to execute i.e. docker.exe.