Having troubles with Angular 6 and node sass on Windows 10 x64?

I was getting all kinds of errors after upgrading my project to Angular 6 on Windows 10 x64, including errors on node sass.
These errors were resolved after I removed the x64 version of Node en installed the Node LTS 10.13.0 x86 (32bits) version on Windows 10 x64.

Errors ng build: Exit status 3221225477.

0 info it worked if it ends with ok

1 verbose cli [ ‘C:\\Program Files\\nodejs\\node.exe’,

1 verbose cli ‘C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js’,

1 verbose cli ‘run’,

1 verbose cli ‘build’ ]

2 info using npm@6.4.1

3 info using node@v10.13.0

4 verbose run-script [ ‘prebuild’, ‘build’, ‘postbuild’ ]

5 info lifecycle entry@0.0.0~prebuild: entry@0.0.0

6 info lifecycle entry@0.0.0~build: entry@0.0.0

7 verbose lifecycle entry@0.0.0~build: unsafe-perm in lifecycle true

8 verbose lifecycle entry@0.0.0~build: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;

C:\Dev\MyProject\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Program Files (x86)\dotnet\;C:\Program Files\Java\jdk1.8.0_181\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\nodejs\;C:\Users\roelv\AppData\Local\Microsoft\WindowsApps;C:\Users\roelv\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\roelv\.dotnet\tools;C:\Users\roelv\AppData\Roaming\npm

9 verbose lifecycle entry@0.0.0~build: CWD: C:\Dev\MyProject\gateway-entry

10 silly lifecycle entry@0.0.0~build: Args: [ ‘/d /s /c’,

10 silly lifecycle ‘npm run translationsBuild && npm run lint:fix && ng build’ ]

11 silly lifecycle entry@0.0.0~build: Returned: code: 3221225725 signal: null

12 info lifecycle entry@0.0.0~build: Failed to exec build script

13 verbose stack Error: entry@0.0.0 build: `npm run translationsBuild && npm run lint:fix && ng build`

13 verbose stack Exit status 3221225725

13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)

13 verbose stack at EventEmitter.emit (events.js:182:13)

13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)

13 verbose stack at ChildProcess.emit (events.js:182:13)

13 verbose stack at maybeClose (internal/child_process.js:962:16)

13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)

14 verbose pkgid entry@0.0.0

15 verbose cwd C:\Dev\MyProject

16 verbose Windows_NT 10.0.17134

17 verbose argv “C:\\Program Files\\nodejs\\node.exe” “C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js” “run” “build”

18 verbose node v10.13.0

19 verbose npm v6.4.1

20 error code ELIFECYCLE

21 error errno 3221225725

22 error entry@0.0.0 build: `npm run translationsBuild && npm run lint:fix && ng build`

22 error Exit status npm install node-sass@beta

23 error Failed at the entry@0.0.0 build script.

23 error This is probably not a problem with npm. There is likely additional logging output above.

24 verbose exit [ 3221225725, true ]

Sonar Cloud and Azure DevOps – Fixing [SQ] Task failed with status FAILED

A pull request build in Azure DevOps failed with the error: “[SQ] Task failed with status FAILED”.

This was the only information given, when de build failed.

Luckily, the manual build gave more information:

Error: /home/vsts/work/1/s/gradlew failed with return code: 1

FAILURE: Build failed with an exception.

2018-10-30T10:51:56.3943110Z

2018-10-30T10:51:56.3943526Z * What went wrong:

2018-10-30T10:51:56.3960616Z Execution failed for task ‘:sonarqube’.

2018-10-30T10:51:56.3961713Z > ‘feature/10691-fix-side-menu-not-working]-when-NOT-admin’ is not a valid branch name. It can only contain ‘A-Z’, ‘a-z’, ‘0-9’, ‘-‘, ‘_’, ‘.’, and ‘/’)

The problem was in the branch name, it accidentally contained a “]” character.

Fix: Calling a function with multiple parameters in PowerShell, merges all parameters in the first parameter as an array

 

When you call a PowerShell function, that expects multiple parameters, with parenthesis, all parameters will be merged in the first parameter, as an array.

The solution is, to call the function with named parameters.

So NOT JoinText($p1, $p2, $p3) but JoinText -p1 $p1 -p2 $p2 -p3 $p3

 

script1.ps1

function JoinText([string]$p1, [string]$p2, [string]$p3) {

return “$p1 $p2 $p3”

}

 

script2-wrong.ps1

$p1 = “some text 1”

$p2 = “some text 2”

$p3 = “some text 3”

$result = JoinText($p1, $p2, $p3)

write-host $result

 

script2-right.ps1

$p1 = “some text 1”

$p2 = “some text 2”

$p3 = “some text 3”

$result = JoinText -p1 $p1 -p2 $p2 -p3 $p3

write-host $result

Calling a function from another PowerShell script file in the same folder with “relative path”

 

If you want to execute a function from another PowerShell script file, you can “dot-source” the file.

The “.” is a special operator in PowerShell that can load another PowerShell script file en import all code in it.

 

Assume both PowerShell scripts are in the same folder, we can use the code in script1.ps1 in script2.ps1 in the following way:

 

PowerShell script1.ps1

 

function ReturnGivenText {

Param(

        [Parameter(Mandatory=$True)]

        [string]$text

    )

    return $text

}

 

PowerShell script2.ps1

$text = ReturnGivenText -text “Hello world”

write-host $text

 

This will output:

Hello world

 

Note: I use the PowerShell >3 global variable $PSScriptRoot, to make the relative path, absolute, so we can use the “.” operator.

 

Fix: Power BI POST request returns a 500 Internal Server Error

When posting to the Power BI api uri: https://api.powerbi.com/v1.0/myorg/groups in PowerShell version 5.1.17134.228, I got the error:

The remote server returned an error: (500) Internal Server Error.

 

I invoked the Power BI rest api with the PowerShell script you can find below.

The error was fixed, when I added -ContentType ‘application/json’ parameter to the InvokeRestMethod

 

 

PowerShell script

 

$clientId = “my-client-id”

$PowerBIUserName = “MyUserName”

$PowerBIUserPassword = “MyUserPassword”

$creds = New-Object “Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential” -ArgumentList $PowerBIUserName,$PowerBIUserPassword

$resourceAppIdURI = “https://analysis.windows.net/powerbi/api”

$authority = “https://login.microsoftonline.com/common/oauth2/authorize”;

$authContext = New-Object “Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext” -ArgumentList $authority

 

# Acquire token

$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $creds)

 

# Create a new group

$auth_header = @{

‘Authorization’=$token.CreateAuthorizationHeader()

}

$uri = “https://api.powerbi.com/v1.0/myorg/groups”

$body = “{`”name`”:`”myNewGroup`”}”

$response = Invoke-RestMethod -Uri $uri -Headers $auth_header -Method POST -Body $body -ContentType ‘application/json’

$target_group_id = $response.id

 

 

 

 

How to fix: VSCode: Cannot launch program ‘…/app/ts’ because corresponding JavaScript cannot be found.

 

I compiled a very simple node.js express application with tsc (TypeScript) on the command line and wanted to debug it with VSCode, but when I pressed F5 I got the error: Cannot launch program ‘…/app/ts’ because corresponding JavaScript cannot be found.

 

I expected the paths in the launch.json to be wrong, but that was not the case.

The problem was that I did not generate *.js.map files.

After I changed the tsconfig.json file, to generate *.js.map files, I could debug the application.

 

tsconfig.json

{

“compileOnSave”: false,

“compilerOptions”: {

“target”: “ES2015”,

“module”: “commonjs”,

“sourceMap”: true,

“strict”: true

}

}

 

 

Preventing multiple WDS disconnects in Chrome on Windows 10, by trusting the self-signed https certificate, generated by Angular CLI ng serve –ssl true

 

If you use ng serve with the parameter –ssl true, to serve your Angular application.

It will generate a self-signed https certificate, so you can run the Angular application on localhost using HTTPS.

By default this certificate is NOT trusted by your browser, so you will get a red cross, left to the url.

Because this certificate is not trusted, you might get multiple WDS disconnect errors in the chrome developer tools console.

Sometimes ending in a never-ending loop.

If you want to trust the self-signed https certificate:

  • click on the red cross (a popup opens)
  • choose Certificate
  • Click on Details
  • Click on Copy to file

 

Press next

 

Choose DER encoded binary X.509 (.CER)

Enter C:\Temp\localhost.cer

 

Press Finish

 

Go to C:\Temp with the explorer and double click on the localhost.cer file.

 

 

Press Install Certificate…

 

Choose “Local Machine” if you want the certificate be trusted for all user of this computer.

 

 

To remove the certificate on Windows 10

  • Open Start, type certmgr.msc
  • Click on “Trusted Root Certification Authorities” > Certificates
  • Right click on localhost and choose Delete

 

How to exit long output from a git command (like git branch -a, git log, git diff)

 

When you have a lot of git branches, the output of git branch -a will be shown in the “less” program.

The first “x” branches are shown and at the bottom the pager cursor will be shown:

 

Now when you press “q”, the less program will quit and you will be returned to the command prompt.

Pressing “h” will show help.

Pressing “arrow down” will scroll one row.

Pressing “page down” will scroll a screen.

When you reach the end of the output, the text “END” will be shown:

 

Press “q” to return to the command prompt

 

See: https://stackoverflow.com/questions/9483757/how-to-exit-git-log-or-git-diff