Skip to Content
0
Jan 07 at 02:41 PM

CAP - cds-ts powershell bug?

262 Views Last edit Jan 07 at 06:19 PM 12 rev

Hi,

When running a CAP application with typescript support using the cds-ts command from powershell, I'm running into following error:

powershell.png

When running the same command from a regular command line shell the project is started perfectly:

commandline.png

I'm running the latest version of the @sap/cds-dk at the time of writing

  • @sap/cds: 5.7.4
  • @sap/cds-compiler: 2.11.4
  • @sap/cds-dk: 4.7.2
  • @sap/cds-foss: 3.0.0
  • Node.js: v17.3.0
  • cap-ts: 1.0.0

Running on Windows 11, tried using powershell v5.1 (delivered by default) and powershell 7.2.1.

Anyone facing the same issue when running typescript enabled CAP applications from powershell?

Best regards,

Geert-Jan

EDIT: a temporary workaround, I adapted the cds-ts.ps1 script commenting out lines 5 -> 9 (ts-node-cwd.exe doesn't exist in my case, by disabling these lines the .exe extension is removed):

script.png

EDIT2: Alternative script could be (first checking the exe variant on windows, else loading the cmd version => cmd extension added to prevent the script from opening in a seperate window)

#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$script=""

if ($IsWindows) {
  if (Test-Path "$basedir/ts-node-cwd.exe"){
    $script = "$basedir/ts-node-cwd.exe"
  } elseif (Test-Path "$basedir/ts-node-cwd.cmd"){
    $script = "$basedir/ts-node-cwd.cmd"
  } elseif (Test-Path "ts-node-cwd.exe"){
    $script = "ts-node-cwd.exe"
  } else {
    $script = "ts-node-cwd.cmd"
  }
} else {
  if (Test-Path "$basedir/ts-node-cwd"){
    $script = "$basedir/ts-node-cwd"
  } else {
    $script = "ts-node-cwd"
  }
}

$ret=0
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
  $input | & "$script"  "$basedir/node_modules/@sap/cds-dk/bin/cds-ts.js" $args
} else {
  & "$script"  "$basedir/node_modules/@sap/cds-dk/bin/cds-ts.js" $args
}
$ret=$LASTEXITCODE
exit $ret

Attachments

powershell.png (98.7 kB)
commandline.png (63.8 kB)
script.png (156.5 kB)