<p>The conflict is occurring between <code>ngc</code> and <code>webpack</code>.  When <code>rimraf aot &amp;&amp; ngc -p ./tsconfig-aot.json</code> is moved to its own script and executed prior to <code>test</code> and <code>build:prod:aot</code> then running <code>test</code> and <code>build:prod:aot</code> with <code>npm-run-all</code> will work as expected.  </p>

<p>Also, running with PowerShell is not necessarily a good idea since it interprets some of the output differently than the Windows shell.  For example, some packages will write out "warnings" to the error stream.</p>

<pre><code>"build:prod:aot": "rimraf aot &amp;&amp; ngc -p ./tsconfig-aot.json",
"webpack:prod": "SET NODE_ENV=production&amp;&amp; webpack",
"test": "SET NODE_ENV=test&amp;&amp; karma start karma.conf.js",
"buildAndTest": "npm-run-all build:prod:aot --parallel test webpack:prod"
</code></pre>

CC BY-SA 3.0
2017-09-18T21:31:44.167Z
2017-09-18T21:31:44.167Z
Aaron
<p>I am running a build process on an on-prem server with TFS 2017 and vNext. The build <em>works</em>, but it takes 20+ minutes. This is an application that does msbuild, ngc, yarn, and karma. I would be totally fine with leaving it the way it is except for the 20 minutes it takes. I found a way to reduce the build by at least 8 minutes by running two of the yarn scripts in parallel. I have been able to successfully run these two scripts in parallel on my laptop, on a VM, and directly on the build server (I remote into the server to do it). However, every attempt to make this work through vNext fails with the exact same error.</p>

<p>Here is the error:  </p>

<pre><code>2017-09-13T20:06:17.9961416Z 13 09 2017 15:06:13.808:ERROR [karma]: TypeError: Cannot read property 'profile' of null
2017-09-13T20:06:17.9961416Z     at factoryCallback (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\Compilation.js:269:13)
2017-09-13T20:06:17.9961416Z     at factory (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:253:5)
2017-09-13T20:06:17.9961416Z     at applyPluginsAsyncWaterfall (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:99:14)
2017-09-13T20:06:17.9961416Z     at D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\tapable\lib\Tapable.js:204:11
2017-09-13T20:06:17.9961416Z     at NormalModuleFactory.params.normalModuleFactory.plugin (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\CompatibilityPlugin.js:52:5)
2017-09-13T20:06:17.9961416Z     at NormalModuleFactory.applyPluginsAsyncWaterfall (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\tapable\lib\Tapable.js:208:13)
2017-09-13T20:06:17.9961416Z     at resolver (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:74:11)
2017-09-13T20:06:17.9961416Z     at process.nextTick (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:205:8)
2017-09-13T20:06:17.9961416Z     at _combinedTickCallback (internal/process/next_tick.js:67:7)
2017-09-13T20:06:17.9961416Z     at process._tickCallback (internal/process/next_tick.js:98:9)
2017-09-13T20:06:17.9961416Z 13 09 2017 15:06:13.823:ERROR [karma]: TypeError: Cannot read property 'profile' of null
2017-09-13T20:06:17.9961416Z     at factoryCallback (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\Compilation.js:269:13)
2017-09-13T20:06:17.9961416Z     at factory (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:253:5)
2017-09-13T20:06:17.9961416Z     at applyPluginsAsyncWaterfall (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:99:14)
2017-09-13T20:06:17.9961416Z     at D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\tapable\lib\Tapable.js:204:11
2017-09-13T20:06:17.9961416Z     at NormalModuleFactory.params.normalModuleFactory.plugin (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\CompatibilityPlugin.js:52:5)
2017-09-13T20:06:17.9961416Z     at NormalModuleFactory.applyPluginsAsyncWaterfall (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\tapable\lib\Tapable.js:208:13)
2017-09-13T20:06:17.9961416Z     at resolver (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:74:11)
2017-09-13T20:06:17.9961416Z     at process.nextTick (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:205:8)
2017-09-13T20:06:17.9961416Z     at _combinedTickCallback (internal/process/next_tick.js:67:7)
2017-09-13T20:06:17.9961416Z     at process._tickCallback (internal/process/next_tick.js:98:9)
</code></pre>

<p>The two scrips that are running are:  </p>

<pre><code>"test": "SET NODE_ENV=test&amp;&amp; karma start karma.conf.js"
</code></pre>

<p>and  </p>

<pre><code>"build:prod:aot": "rimraf aot &amp;&amp; ngc -p ./tsconfig-aot.json &amp;&amp; SET NODE_ENV=production&amp;&amp; webpack"
</code></pre>

<p>The error is coming from karma. I get the same error from vNext no matter how I try to run these two scripts. I have tried  </p>

<ul>
<li>Adding a script to run them with the <code>concurrently</code> npm package. Executed using a Windows batch command.</li>
<li>Adding a script to run them with the <code>npm-run-all</code> npm package. Executed using a Windows batch command.</li>
<li>Running a powershell .ps1 script to run each command with Start-Job.</li>
<li>Running a .bat file that in turn runs two other .bat files, one for each script.</li>
</ul>

<p>In every case I get the exact same error from vNext. In every case I get the expected result when running from my laptop, a VM, and when running the script while logged into the build server.  </p>

<p>What am I missing here? Why is vNext behaving differently?</p>

CC BY-SA 3.0
2017-09-14T14:20:54.200Z
I assume your build are not run through a CMD call directly but by a direct system call, as such the SET command is no op and doesn't populate the environment variable for the next chained command. Prepend them with `cmd /c ` and you should be OK.
Tensibai
CC BY-SA 3.0
2017-09-14T15:03:50.117Z
I'm trying to understand what you mean,but it's not making sense to me. I setup the build to run my scripts with a Command Line task and a PowerShell task.  Both end up giving me the same result.
Aaron
CC BY-SA 3.0
2017-09-14T15:17:37.563Z
That's an assumption, I may be wrong but the error looks like it's searching for a profile valued by environment variable NODE_ENV which is filled by Set which works in console but not within the build system. I'm not using TFS so it's just a guess
Tensibai
CC BY-SA 3.0
2017-09-14T15:28:40.723Z
If SET doesn't work in the build environment, then that would explain why I can remote into the build server and run the script and it succeeds.  I'm going to try a different approach using a Run Script task to execute a .bat file.  The Run Script task has an option to allow it to modify the environment.
Aaron
CC BY-SA 3.0
2017-09-14T16:08:30.273Z
Well, that didn't work.  Still getting the same error.
Aaron
CC BY-SA 3.0
2017-09-15T18:30:14.313Z
[This seems to be somewhat related.](https://github.com/yarnpkg/yarn/issues/683)
Aaron
CC BY-SA 3.0
2017-09-18T15:54:44.667Z
It looks like ngc is interfering with webpack. If I move `rimraf aot && ngc -p ./tsconfig-aot.json` to its own script I am then able to run `test` and `build:prod:aot` in parallel.
Aaron
<powershell><tfs><node.js>
Why is my build script only failing when it is run in a vNext build?
Aaron
# Why is my build script only failing when it is run in a vNext build?

(Asked by: username_0 on 2017-09-14)

I am running a build process on an on-prem server with TFS 2017 and vNext. The build works, but it takes 20+ minutes. This is an application that does msbuild, ngc, yarn, and karma. I would be totally fine with leaving it the way it is except for the 20 minutes it takes. I found a way to reduce the build by at least 8 minutes by running two of the yarn scripts in parallel. I have been able to successfully run these two scripts in parallel on my laptop, on a VM, and directly on the build server (I remote into the server to do it). However, every attempt to make this work through vNext fails with the exact same error.
Here is the error:  
2017-09-13T20:06:17.9961416Z 13 09 2017 15:06:13.808:ERROR [karma]: TypeError: Cannot read property 'profile' of null
2017-09-13T20:06:17.9961416Z     at factoryCallback (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\Compilation.js:269:13)
2017-09-13T20:06:17.9961416Z     at factory (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:253:5)
2017-09-13T20:06:17.9961416Z     at applyPluginsAsyncWaterfall (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:99:14)
2017-09-13T20:06:17.9961416Z     at D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\tapable\lib\Tapable.js:204:11
2017-09-13T20:06:17.9961416Z     at NormalModuleFactory.params.normalModuleFactory.plugin (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\CompatibilityPlugin.js:52:5)
2017-09-13T20:06:17.9961416Z     at NormalModuleFactory.applyPluginsAsyncWaterfall (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\tapable\lib\Tapable.js:208:13)
2017-09-13T20:06:17.9961416Z     at resolver (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:74:11)
2017-09-13T20:06:17.9961416Z     at process.nextTick (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:205:8)
2017-09-13T20:06:17.9961416Z     at _combinedTickCallback (internal/process/next_tick.js:67:7)
2017-09-13T20:06:17.9961416Z     at process._tickCallback (internal/process/next_tick.js:98:9)
2017-09-13T20:06:17.9961416Z 13 09 2017 15:06:13.823:ERROR [karma]: TypeError: Cannot read property 'profile' of null
2017-09-13T20:06:17.9961416Z     at factoryCallback (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\Compilation.js:269:13)
2017-09-13T20:06:17.9961416Z     at factory (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:253:5)
2017-09-13T20:06:17.9961416Z     at applyPluginsAsyncWaterfall (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:99:14)
2017-09-13T20:06:17.9961416Z     at D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\tapable\lib\Tapable.js:204:11
2017-09-13T20:06:17.9961416Z     at NormalModuleFactory.params.normalModuleFactory.plugin (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\CompatibilityPlugin.js:52:5)
2017-09-13T20:06:17.9961416Z     at NormalModuleFactory.applyPluginsAsyncWaterfall (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\tapable\lib\Tapable.js:208:13)
2017-09-13T20:06:17.9961416Z     at resolver (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:74:11)
2017-09-13T20:06:17.9961416Z     at process.nextTick (D:\Agents\Agent1\_work\126\s\Src\BFY.Admin.Web\node_modules\webpack\lib\NormalModuleFactory.js:205:8)
2017-09-13T20:06:17.9961416Z     at _combinedTickCallback (internal/process/next_tick.js:67:7)
2017-09-13T20:06:17.9961416Z     at process._tickCallback (internal/process/next_tick.js:98:9)

The two scrips that are running are:  
"test": "SET NODE_ENV=test&& karma start karma.conf.js"

and  
"build:prod:aot": "rimraf aot && ngc -p ./tsconfig-aot.json && SET NODE_ENV=production&& webpack"

The error is coming from karma. I get the same error from vNext no matter how I try to run these two scripts. I have tried  

Adding a script to run them with the concurrently npm package. Executed using a Windows batch command.
Adding a script to run them with the npm-run-all npm package. Executed using a Windows batch command.
Running a powershell .ps1 script to run each command with Start-Job.
Running a .bat file that in turn runs two other .bat files, one for each script.

In every case I get the exact same error from vNext. In every case I get the expected result when running from my laptop, a VM, and when running the script while logged into the build server.  
What am I missing here? Why is vNext behaving differently?

**Tags:** powershell, tfs, node.js

> **Comments:**
> **username_1**: I assume your build are not run through a CMD call directly but by a direct system call, as such the SET command is no op and doesn't populate the environment variable for the next chained command. Prepend them with `cmd /c ` and you should be OK.  
> **username_0**: I'm trying to understand what you mean,but it's not making sense to me. I setup the build to run my scripts with a Command Line task and a PowerShell task.  Both end up giving me the same result.  
> **username_1**: That's an assumption, I may be wrong but the error looks like it's searching for a profile valued by environment variable NODE_ENV which is filled by Set which works in console but not within the build system. I'm not using TFS so it's just a guess  
> **username_0**: If SET doesn't work in the build environment, then that would explain why I can remote into the build server and run the script and it succeeds.  I'm going to try a different approach using a Run Script task to execute a .bat file.  The Run Script task has an option to allow it to modify the environment.  
> **username_0**: Well, that didn't work.  Still getting the same error.  
> **username_0**: [This seems to be somewhat related.](https://github.com/yarnpkg/yarn/issues/683)  
> **username_0**: It looks like ngc is interfering with webpack. If I move `rimraf aot && ngc -p ./tsconfig-aot.json` to its own script I am then able to run `test` and `build:prod:aot` in parallel.  

---

## 1 answers

### Answer by username_0 on 2017-09-18. Score: 1

The conflict is occurring between ngc and webpack.  When rimraf aot && ngc -p ./tsconfig-aot.json is moved to its own script and executed prior to test and build:prod:aot then running test and build:prod:aot with npm-run-all will work as expected.  
Also, running with PowerShell is not necessarily a good idea since it interprets some of the output differently than the Windows shell.  For example, some packages will write out "warnings" to the error stream.
"build:prod:aot": "rimraf aot && ngc -p ./tsconfig-aot.json",
"webpack:prod": "SET NODE_ENV=production&& webpack",
"test": "SET NODE_ENV=test&& karma start karma.conf.js",
"buildAndTest": "npm-run-all build:prod:aot --parallel test webpack:prod"


---

