Bash SyntaxError in node module (Angular clone)

69 Views Asked by At

I have cloned an Angular project and got the following error message

"C:\Program Files\nodejs\npm.cmd" run start


> [email protected] start
> node --max_old_space_size=4096 ./node_modules/.bin/ng serve

E:\me\Projekt\cloneFe\node_modules\.bin\ng:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.16.1

Process finished with exit code 1

my ng file lookks like this.

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  exec "$basedir/node"  "$basedir/../@angular/cli/bin/ng" "$@"
else
  exec node  "$basedir/../@angular/cli/bin/ng" "$@"
fi

i'm Running that on IntelliJ ultimate in Windows

I have tried another "node" version with vola but the error remains constant regardless of the setup.

Especially since it's a bash error, I don't know if node.js plays a role at all. Here is the comparison in a self-made angular project of the ng file

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  exec "$basedir/node"  "$basedir/../@angular/cli/bin/ng.js" "$@"
else 
  exec node  "$basedir/../@angular/cli/bin/ng.js" "$@"
fi
1

There are 1 best solutions below

0
On

Nested executions is a bad idea in bash (mix of $(...) and also nested "...").

Try to replace:

basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

with:

slash_progname=$(echo -n "$0" | sed -e 's,\\,/,g')
basedir=$(dirname "$slash_progname")

You also could replace echo + sed with:

slash_progname="${0//\\//}"

So, the line should be:

basedir=$(dirname "${0//\\//}")

And finally:

slash_progname="${0//\\//}"
basedir="${slash_progname%/*}"