node.js Gradle“...在Mac上发生了启动过程'命令'npm''”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33546759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle "... occurred starting process 'command 'npm''" on Mac
提问by Andrei Petrik
I have MacOS with IntelliJ Idea installed. I'm using Gradle (gradle-2.4) for building the project. I have NodeJS and NPM installed on the Mac and available from the shell.
我有安装了 IntelliJ Idea 的 MacOS。我正在使用 Gradle (gradle-2.4) 来构建项目。我在 Mac 上安装了 NodeJS 和 NPM,并且可以从 shell 获取。
MacBook:~ user$ node -v
v4.2.2
MacBook:~ user$ npm -v
2.14.7
When running Gradle task that uses NODE/NPM, it fails with the following error (in current example it is NPM).
运行使用 NODE/NPM 的 Gradle 任务时,它失败并显示以下错误(在当前示例中为 NPM)。
* What went wrong:
Execution failed for task ':module:task'.
> A problem occurred starting process 'command 'npm''
The error stack trace from Gradle is the following.
Gradle 的错误堆栈跟踪如下。
Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':module:task'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.access0(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter.proceed(DefaultBuildExecuter.java:68)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:43)
at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:30)
at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:119)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.call(ForwardClientInput.java:71)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.call(ForwardClientInput.java:69)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.run(StartBuildOrRespondWithBusy.java:46)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator.run(DaemonStateCoordinator.java:246)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl.run(DefaultExecutorFactory.java:64)
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'npm''
at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:196)
at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:325)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:83)
... 1 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'npm'
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:65)
... 1 more
Caused by: java.io.IOException: Cannot run program "npm" (in directory "/<project path>"): error=2, No such file or directory
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
... 3 more
Caused by: java.io.IOException: error=2, No such file or directory
... 4 more
So it looks like Gradle is trying to find NPM in the project absolute directory and doesn't use Mac PATH environment variable. Anyone knows how to avoid/workaround this? I cannot use absolute path for NODE/NPM as the team is shared and using different OSes (Linux, MacOS). Any ideas? :)
所以看起来 Gradle 试图在项目绝对目录中找到 NPM 并且不使用 Mac PATH 环境变量。任何人都知道如何避免/解决这个问题?我不能为 NODE/NPM 使用绝对路径,因为团队是共享的并且使用不同的操作系统(Linux、MacOS)。有任何想法吗?:)
回答by clinyong
I stop the gradle daemon by running
我通过运行来停止 gradle 守护进程
$ ./gradlew --stop
rerun the gradle command and fix it.
重新运行 gradle 命令并修复它。
回答by Yohan Liyanage
I had a similar issue and in my case, problem was that when I ran it from IntelliJ, Gradle was unable to access path to find out where node / npm is. I was using the gradle-gulp-plugin and enabling automatic download of node resolved the problem.
我有一个类似的问题,就我而言,问题是当我从 IntelliJ 运行它时,Gradle 无法访问路径以找出节点 / npm 的位置。我正在使用 gradle-gulp-plugin 并启用节点的自动下载解决了这个问题。
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath('be.filipblondeel.gradle:gradle-gulp-plugin:0.1')
}
}
node {
// Version of node to use.
version = '0.12.0'
// Enabled the automatic download.
download = true
}
回答by Vic Torious
Might be usefull for someone:
可能对某人有用:
In my case the problem was, that I had Android Studio running. Had to quit it first, then everything worked fine again.
就我而言,问题是我运行了 Android Studio。不得不先退出它,然后一切又正常了。
回答by prag
I had the same problem and got it resolved by running the command:
我遇到了同样的问题,并通过运行以下命令解决了它:
gradle --stop
回答by RomanKn
Might be helpfull:
可能有帮助:
sudo launchctl config user path $PATH
sudo launchctl 配置用户路径 $PATH
"To take effect might have to restart your machine"
“要生效可能需要重启你的机器”
回答by Moonwalker
The answer is this is trivial it turns out. Solution is applicable to ANY application.
答案是事实证明这是微不足道的。解决方案适用于任何应用程序。
The reason for the error is that none of the visual apps on Mac OS X use a user shell so whatever you have in your local profile settings such as ~/.bash_profilesimply does not take when Studio is launched. There is a good workaround:
错误的原因是 Mac OS X 上的任何可视化应用程序都没有使用用户 shell,因此您在本地配置文件设置中的任何内容(例如~/.bash_profile在 Studio 启动时都不会使用)。有一个很好的解决方法:
- from terminal, go to this directory or where ever your Studio app (or any other app) is installed:
- 从终端,转到此目录或安装 Studio 应用程序(或任何其他应用程序)的位置:
cd /Applications/Android Studio.app/Contents/MacOS
- Move the studio executable to
studio_app(or whatever is your executable name)
- 将工作室可执行文件移动到
studio_app(或任何您的可执行文件名称)
mv $executable$ $executable$_app
- Create a new text file, call it
$executable$, and populate it like this. Here I am using mybash_profile.
- 创建一个新的文本文件,调用它
$executable$,然后像这样填充它。在这里,我使用我的bash_profile.
#!/bin/sh
. ~/.bash_profile
logger "`dirname \"chmod +x $executable$
\"`/$executable$_app"
exec "`dirname \"WARN - nal.AbstractExternalSystemTask - error=2, No such file or directory
com.intellij.openapi.externalSystem.model.ExternalSystemException: error=2, No such file or directory
at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:228)
\"`/$executable$_app" $@
- Close the studio file. From shell change permissions:
- 关闭工作室文件。从外壳更改权限:
And that is it. Relaunch Studio app normally and now it has inherited all your settings from bash_profile, including path to node etc.
就是这样。正常重新启动 Studio 应用程序,现在它继承了您的所有设置bash_profile,包括节点路径等。
Substitute $executable$with the name of your exe file. For Android Studio it would be just studio. For IntelliJ it should be just intellij (double check).
替换$executable$为您的 exe 文件的名称。对于 Android Studio,它只是工作室。对于 IntelliJ,它应该只是 intellij(仔细检查)。
回答by Jason White
I ran into this same issue attempting to run Gradle tasks that executed commands such as node and npm from the Gradle plugin in Intellij. You can see from the stack trace that the Gradle plugin is attempting to execute external system commands and it is getting errors such as this:
我在尝试运行从 Intellij 中的 Gradle 插件执行 node 和 npm 等命令的 Gradle 任务时遇到了同样的问题。您可以从堆栈跟踪中看到 Gradle 插件正在尝试执行外部系统命令,并且收到如下错误:
##代码##You can reproduce this error from the command line if you remove the executables (ie node, npm) from the path, which tells me that something about the plugin is not honoring the environment path.
如果从路径中删除可执行文件(即节点、npm),您可以从命令行重现此错误,这告诉我有关插件的某些内容不符合环境路径。
My Gradle plugin is using the projects gradlew (gradle wrapper version 2.3), so I attempted to point the plugin at a more recent Gradle installation on my system (version 2.10) and it worked.
我的 Gradle 插件正在使用项目 gradlew(gradle 包装器版本 2.3),因此我尝试将该插件指向我系统(版本 2.10)上更新的 Gradle 安装并且它工作正常。
I then resolved my issue by regenerating the gradle wrapper for my project and then setting the IntelliJ Gradle plugin to point back to my wrapper.
然后我通过为我的项目重新生成 gradle 包装器解决了我的问题,然后将 IntelliJ Gradle 插件设置为指向我的包装器。
I have no idea what the original problem was.
我不知道原来的问题是什么。

