如何安装gulp 4

时间:2015-10-30 06:09:57

标签: npm gulp gulp-watch

我一直在使用gulp-watch。当前版本的gulp-watch依赖于调用gulp.parrallel。此调用仅适用于gulp 4。

然而,通过npm repo无法获得gulp 4。 npm info gulp dist-tags返回:{ latest: '3.9.0' }

我可以看到git repo中有一个4.0分支。但是尝试使用此命令的变体安装它会失败:npm install https://github.com/gulpjs/gulp#v4.0.0

11 个答案:

答案 0 :(得分:30)

npm install gulpjs/gulp.git#4.0 --save-dev

答案 1 :(得分:21)

Gulp已从其GitHub存储库中删除了4.0分支,因此以前使用npm install gulpjs/gulp.git#4.0 --save-dev进行安装的方法不再起作用。

他们在其README中指出,安装gulp 4.0的正确方法是运行以下命令:

npm install gulp@next

答案 2 :(得分:16)

# Uninstall previous Gulp installation and related packages, if any
$ npm rm gulp -g
$ npm rm gulp-cli -g
$ cd [your-project-dir/]
$ npm rm gulp --save-dev
$ npm rm gulp --save
$ npm rm gulp --save-optional
$ npm cache clean # for npm < v5

# Install the latest Gulp CLI tools globally
$ npm install gulpjs/gulp-cli -g

# Install Gulp 4 into your project as dev dependency
$ npm install gulp --save-dev

# Check the versions installed. Make sure your versions are not lower than shown.
$ gulp -v
---
[10:48:35] CLI version 2.0.1
[10:48:35] Local version 4.0.0

详细信息位于此博客页面:https://demisx.github.io/gulp4/2015/01/15/install-gulp4.html

答案 3 :(得分:15)

运行以下命令以检查计算机上安装的gulp cli的版本。

gulp -v

如果您未运行版本4,请执行以下操作在您的计算机上全局安装gulp。

npm uninstall -g gulp
npm install -g "gulpjs/gulp#4.0"

现在在本地安装gulp 4

npm uninstall gulp --save-dev
npm install "gulpjs/gulp#4.0" --save-dev

答案 4 :(得分:2)

安装gulp-4, CLI 版本必须 1.2.2 ,这将支持gulp 4.0

安装 gulp-cli 1.2.2 运行sudo npm install gulp-cli@1.2.2 -g

并安装 gulp 4.0 运行npm install 'gulpjs/gulp.git#4.0' --save-dev

运行 gulp -v 命令

你应该得到

[11:38:36] CLI版本1.2.2

[11:38:36]本地版本4.0.0-alpha.2

GitHub

上的类似问题

答案 5 :(得分:2)

2018年11月»npm审核说要运行:npm install --save-dev gulp@4.0.0

答案 6 :(得分:2)

从2018年12月28日开始,以下命令在本地安装版本4时应该可以正常工作。

npm i -D gulp

答案 7 :(得分:1)

我的安装有点不同。

正在运行

npm install 'gulpjs/gulp.git#4.0' --save-dev

或者

npm install 'gulpjs/gulp#4.0' --save-dev

给我一​​个错误:

  

npm ERR!代码EINVALIDTAGNAME npm ERR!无效的标签名称“gulp#4.0”:标签   可能没有任何encodeURIComponent编码的字符。

NB 我只是在安装本地gulp-4时遇到问题所以我看了上一次package.json安装,看到了这个:

"gulp": "github:gulpjs/gulp#4.0",

所以我的举措是用

安装本地gulp
npm install "github:gulpjs/gulp#4.0" --save-dev

这很有效,成功安装了本地gulp 4.

[15:45:55] CLI version 1.4.0
[15:45:55] Local version 4.0.0-alpha.2

答案 8 :(得分:1)

我写了一个批处理文件,该文件根据@demisx的回答进行工作。

我遇到的问题是缺少npm config参数'prefix',所以我的全局目录是节点二进制目录。 我可以肯定情况并非总是如此,但是我可以从项目根目录运行此脚本来(重新)设置它:

@ECHO OFF
echo configuring npm
set USERNAME=<enter username>
set USERPROFILE=C:\Users\%USERNAME%
set APPDATA=%USERPROFILE%\AppData\Roaming
call npm config set prefix %APPDATA%\npm

SET DIR_PROJECT="D:/stuff/plugins/wallpaper_engine/raintime-dev"

echo Uninstall previous Gulp installation and related packages, if any
call npm rm gulp -g
call npm rm gulp-cli -g

echo cd %DIR_PROJECT%
cd /D %DIR_PROJECT%

call npm rm gulp --save-dev
call npm rm gulp --save
call npm rm gulp --save-optional
call npm cache clean

echo Install the latest Gulp CLI tools globally
call npm install gulpjs/gulp-cli -g

echo Install Gulp 4 into your project from 4.0 GitHub branch as dev dependency
rem call npm install gulpjs/gulp#4.0 --save-dev
call npm install gulpjs/gulp --save-dev

echo Check the versions installed.

call gulp -v

pause

脚本最终显示了这一点:

[14:59:48] CLI version 2.0.1
[14:59:48] Local version 4.0.0

希望有帮助!

答案 9 :(得分:1)

我通过运行以下方法解决了该问题:

which gulp
rm -rf /usr/local/bin/gulp
npm i -g gulp

答案 10 :(得分:0)

Windows仍然无法升级。另一篇Linux帖子中的以下命令似乎将其清除,然后成功。

似乎无法将gulp从3.9升级到4.0

卸载先前的Gulp安装和相关软件包,如果有的话:

Caused by: org.gradle.tooling.BuildException: Failed to process: ........./app/build/intermediates/transforms/sensorsAnalyticsAutoTrack/googlePlay/release/223.jar
        at com.android.build.gradle.internal.dexing.DexWorkAction.run(DexWorkAction.kt:59)
        at org.gradle.workers.internal.AdapterWorkAction.execute(AdapterWorkAction.java:57)
        at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
        at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:67)
        at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:63)
        at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:97)
        at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:63)
        at org.gradle.workers.internal.NoIsolationWorkerFactory$1$$Lambda$839.00000000978A4420.execute(Unknown Source)
        at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
        at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
      
Caused by: java.lang.NullPointerException
        at Version.fakeStackEntry(Version_2.0.88.java:0)
        at java.util.IdentityHashMap.containsKey(IdentityHashMap.java:352)
        at java.util.Collections$SetFromMap.contains(Collections.java:5513)
        at com.android.tools.r8.dex.P$g.a(:2)
        at com.android.tools.r8.dex.P$g.addString(:1)
        at com.android.tools.r8.graph.f0.collectIndexedItems(:3)
        at com.android.tools.r8.graph.Z.collectIndexedItems(:2)
        at com.android.tools.r8.graph.V.collectIndexedItems(:2)
        at com.android.tools.r8.graph.T.collectIndexedItems(:4)
        at com.android.tools.r8.graph.V.collectIndexedItems(:1)
        at com.android.tools.r8.graph.V.a(:2)
        at com.android.tools.r8.graph.V$$Lambda$3484.000000009B598550.accept(Unknown Source)
        at com.android.tools.r8.graph.V.a(:8)
        at com.android.tools.r8.graph.V.a(:1)
        at com.android.tools.r8.graph.b0.b(:2)
        at com.android.tools.r8.graph.b0.collectIndexedItems(:23)
        at com.android.tools.r8.graph.V.collectIndexedItems(:1)
        at com.android.tools.r8.dex.P.a(:48)
        at com.android.tools.r8.dex.P$i.a(:42)
        at com.android.tools.r8.dex.P$e.a(:77)
        at com.android.tools.r8.dex.b.a(:15)
        at com.android.tools.r8.dex.b.b(:24)
        at com.android.tools.r8.D8.d(:92)
        at com.android.tools.r8.D8.b(:1)
        at com.android.tools.r8.D8$$Lambda$3181.00000000A24B3020.run(Unknown Source)
        at com.android.tools.r8.utils.W.a(:30)
        at com.android.tools.r8.D8.run(:11)
        at com.android.builder.dexing.D8DexArchiveBuilder.convert(D8DexArchiveBuilder.java:116)
        ... 36 more