NodeJS 从powershell调用节点

fruv7luv  于 9个月前  发布在  Node.js
关注(0)|答案(1)|浏览(90)

我正在尝试为Github本地托管的action runner创建一个yml文件,它调用一个名为“terser”的npm模块来缩小js和css。

- name: Minify_JS
  if:  ${{ contains(inputs.SHOULD_MINIFY, 'true') }}
  run: | 
      $folder = "C:\Build\${{inputs.REPOS_NAME}}"
      $files = get-childitem $folder -recurse -force -include *.js    
      foreach($file in $files){ D:\Progra~1\nodejs\node.exe C:\Build\node_modules\terser\bin\terser --compress --mangle --output $file.FullName -- $file.FullName    }
      echo "JS minified!"
      #java -jar  D:\Atlassian\Bamboo-Ant-Tasks\lib\yuicompressor-2.4.7.jar $file.FullName -o $file.FullName

因此,有效的代码行是D:\Progra~1\nodejs\node.exe C:\Build\node_modules\terser\bin\terser --compress --mangle --output $file.FullName -- $file.FullName
这一行将从命令行工作,但当我通过动作运行器运行它时,我得到了下面的错误。

D:\Progra~1\nodejs\node.exe : The term 'D:\Progra~1\nodejs\node.exe' is not recognized as the name of a cmdlet,

函数、脚本文件或可操作程序。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。地址:C:\actions-runner_work_temp\beb4cf2f-8512-429c-8624-a9493ed16748.ps1:4 char:27

  • foreach($file in $files){D:\footer1\nodejs\node.exe C:\Build\node_m.
~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • 分类信息:ObjectNotFound:(D:\Progra~1\nodejs\node.exe:String)[],ParentContainsErrorRecordExcept离子
  • FullyQualifiedErrorId:CommandNotFoundException
ax6ht2ek

ax6ht2ek1#

结果是“环境变量不能热重新加载,所以每次新命令添加到路径时,power shell,cmd或GitHub服务都需要重新启动,以便它们可以加载新环境......”所以在我们的案例中,我们只是重新启动了安装在windows上的Github Action Runner服务,并修复了这个问题

相关问题