git-bash: SyntaxError: missing ) 在参数列表之后

use*_*629 6 windows git-bash vue.js visual-studio-code nuxt.js

我正在尝试使用以下命令在 nuxt 项目上使用 vscode 设置调试:

https://medium.com/@justin.ramel/nuxt-js-debugging-in-visual-studio-code-822ff9d51c77
Run Code Online (Sandbox Code Playgroud)

我已经到了:

$ npm run dev-debug

> nuxt4@1.0.0 dev-debug E:\ENVS\js\nuxt4
> node --inspect node_modules/.bin/nuxt

Debugger listening on ws://127.0.0.1:9229/6f869cb6-7166-4182-b841-a528917d88fd
For help, see: https://nodejs.org/en/docs/inspector
E:\ENVS\js\nuxt4\node_modules\.bin\nuxt:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
        ^^^^^^^

SyntaxError: missing ) after argument list
    at new Script (vm.js:83:7)
    at createScript (vm.js:267:10)
    at Object.runInThisContext (vm.js:319:10)
    at Module._compile (internal/modules/cjs/loader.js:684:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
    at executeUserCode (internal/bootstrap/node.js:342:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nuxt4@1.0.0 dev-debug: `node --inspect node_modules/.bin/nuxt`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nuxt4@1.0.0 dev-debug script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)

整个nuxt文件是:

https://medium.com/@justin.ramel/nuxt-js-debugging-in-visual-studio-code-822ff9d51c77
Run Code Online (Sandbox Code Playgroud)

编辑:

我尝试进行更改并得到:

> node --inspect node_modules/.bin/nuxt

Debugger listening on ws://127.0.0.1:9229/458bafd6-1d8c-4a2b-8ec2-5ddc8b4f0fda
For help, see: https://nodejs.org/en/docs/inspector
E:\ENVS\js\nuxt4\node_modules\.bin\nuxt:1
(function (exports, require, module, __filename, __dirname) {   #!/bin/sh
                                                                ^

SyntaxError: Invalid or unexpected token
    at new Script (vm.js:83:7)
    at createScript (vm.js:267:10)
    at Object.runInThisContext (vm.js:319:10)
    at Module._compile (internal/modules/cjs/loader.js:684:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
    at executeUserCode (internal/bootstrap/node.js:342:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nuxt4@1.0.0 dev-debug: `node --inspect node_modules/.bin/nuxt`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nuxt4@1.0.0 dev-debug script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)

我如何让这个工作?

Joh*_*Eye 9

我有一个部分解释和修复,应该对某些人有用。

原因

问题的根本原因是node获取了 Bash 或 Windows shell 脚本作为参数。.bin如果您查看诸如 中的文件node_modules\.bin\nuxt,您会发现这些实际上是 shell 脚本,它们应该返回 JavaScript 文件的真实路径,该文件应该node作为参数传递给该文件。

我不知道这在 Linux 下是如何工作的,但是当我git-bash在 Linux VM 上使用相同的代码库工作得很好时,我就遇到过这个问题,所以它绝对是特定于环境的。如果有人对此有答案,我很乐意将其添加到问题中。

解决方案

不要将文件传递.binnode. 相反,找到真实文件的路径并传递它。在这种情况下,它node_modules/nuxt/bin/nuxt.js和许多库遵循相同的原则,但有时很难找到,例如Angularnode_modules/@angular/cli/bin/ng我的系统上。

一句警告

此解决方案绕过了文件的定位方式JavaScript,并且可能在库更新后停止工作。或者它可能不适用于所有系统。我不是node开发人员,只是在尝试运行别人的代码时才发现它。对于我的用例来说,这是一个足够好的解决方案,但可能不适合您。


Yed*_*hin 1

我不确定这是否是问题所在,但仍然尝试一下。就像我过去在使用遗留反引号``时遇到了一些奇怪的错误。

使用 $(...) 表示法而不是传统的反引号`...`

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

case $(uname) in
    *CYGWIN*) basedir=$(cygpath -w "$basedir");;
esac

if [ -x "$basedir/node" ]; then
"$basedir/node"  "$basedir/../nuxt/bin/nuxt.js" "$@"
ret=$?
else 
node  "$basedir/../nuxt/bin/nuxt.js" "$@"
ret=$?
fi
exit $ret
Run Code Online (Sandbox Code Playgroud)