当前位置: 首页 > 工具软件 > ExecJS > 使用案例 >

执行execjs报错execjs._exceptions.ProcessExitedWithNonZeroStatus

陶高峯
2023-12-01
Traceback (most recent call last):
  File "test_js.py", line 12, in <module>
    res = js.call("test")
  File "/usr/local/python3/lib/python3.7/site-packages/execjs/_abstract_runtime_context.py", line 37, in call
    return self._call(name, *args)
  File "/usr/local/python3/lib/python3.7/site-packages/execjs/_external_runtime.py", line 92, in _call
    return self._eval("{identifier}.apply(this, {args})".format(identifier=identifier, args=args))
  File "/usr/local/python3/lib/python3.7/site-packages/execjs/_external_runtime.py", line 78, in _eval
    return self.exec_(code)
  File "/usr/local/python3/lib/python3.7/site-packages/execjs/_abstract_runtime_context.py", line 18, in exec_
    return self._exec_(source)
  File "/usr/local/python3/lib/python3.7/site-packages/execjs/_external_runtime.py", line 85, in _exec_
    output = self._exec_with_tempfile(source)
  File "/usr/local/python3/lib/python3.7/site-packages/execjs/_external_runtime.py", line 127, in _exec_with_tempfile
    self._fail_on_non_zero_status(ret, stdoutdata, stderrdata)
  File "/usr/local/python3/lib/python3.7/site-packages/execjs/_external_runtime.py", line 134, in _fail_on_non_zero_status
    raise ProcessExitedWithNonZeroStatus(status=status, stdout=stdoutdata, stderr=stderrdata)
execjs._exceptions.ProcessExitedWithNonZeroStatus: (101, '', '/tmp/execjsextscsjc.js:2:0 Expected an operand but found const\nconst s=()=>Array.form({length:16}).,ap(()=>Math.round(61*Math.random()));\n^\n/tmp/execjsextscsjc.js:2:34 Expected ; but found )\nconst s=()=>Array.form({length:16}).,ap(()=>Math.round(61*Math.random()));\n                                  ^\n/tmp/execjsextscsjc.js:5:0 Expected an operand but found const\nconst e = s();\n^\n')

在centos环境执行执行py文件的时候,嵌入了js代码段,执行报错如上,原因可能是因为没有安装node环境,

安装node环境应该就好了,下面为安装node环境

wget https://nodejs.org/dist/v10.8.0/node-v10.8.0-linux-x64.tar.gz
tar -xzvf node-v10.8.0-linux-x64.tar.gz
mv node-v10.8.0-linux-x64.tar.gz node
cd node/bin
pwd   //获取当前路径
vim ~/.bash_profile  //配置环境变量
    export PATH=$PATH:/root/node/bin
source ~/.bash_profile

配置好以上环境,再次执行成功!如果还是不成功,尝试断开连接,重新连接试一下,说不定就可以了呢!!!

如果windows或者ios报类似的错误,先检查有没有安装node,并配置好环境变量!

 类似资料: