问题呈现:

PS D:\Code\Java\ideaWorkspace\renren-fast-vue> npm run build

> renren-fast-vue@1.2.2 build D:\Code\Java\ideaWorkspace\renren-fast-vue
> gulp fs.js:36
} = primordials;
^ ReferenceError: primordials is not defined
at fs.js:36:5
at req_ (D:\Code\Java\ideaWorkspace\renren-fast-vue\node_modules\natives\index.js:143:24)
at Object.req [as require] (D:\Code\Java\ideaWorkspace\renren-fast-vue\node_modules\natives\index.js:55:10)
at Object.<anonymous> (D:\Code\Java\ideaWorkspace\renren-fast-vue\node_modules\graceful-fs\fs.js:1:37)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
npm ERR! errno 1
npm ERR! renren-fast-vue@1.2.2 build: `gulp`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the renren-fast-vue@1.2.2 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:

解决办法:

1.升级gulp到4.0

npm install -g gulp-cli
npm install --save-dev gulp@4

查看gulp 版本:

gulp -v

2.修改gulpfile.js文件

该文件在renren-fast-vue 项目的根目录

修改的原因时:gulp 4.0的语法跟以往版本不同。

修改前的gulpfile.js

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var path = require('path');
var del = require('del'); var distPath = path.resolve('./dist');
var version = ''; // 版本号
var versionPath = ''; // 版本号路径
var env = ''; // 运行环境 // 创建版本号(年月日时分)
(function () {
var d = new Date();
var yy = d.getFullYear().toString().slice(2);
var MM = d.getMonth() + 1 >= 10 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1);
var DD = d.getDate() >= 10 ? d.getDate() : '0' + d.getDate();
var h = d.getHours() >= 10 ? d.getHours() : '0' + d.getHours();
var mm = d.getMinutes() >= 10 ? d.getMinutes() : '0' + d.getMinutes();
version = yy + MM + DD + h + mm;
versionPath = distPath + '/' + version;
})(); // 编译
gulp.task('build', $.shell.task([ 'node build/build.js' ])); // 创建版本号目录
gulp.task('create:versionCatalog', ['build'], function () {
return gulp.src(`${distPath}/static/**/*`)
.pipe(gulp.dest(`${versionPath}/static/`))
}); // 替换${versionPath}/static/js/manifest.js window.SITE_CONFIG.cdnUrl占位变量
gulp.task('replace:cdnUrl', ['create:versionCatalog'], function () {
return gulp.src(`${versionPath}/static/js/manifest.js`)
.pipe($.replace(new RegExp(`"${require('./config').build.assetsPublicPath}"`, 'g'), 'window.SITE_CONFIG.cdnUrl + "/"'))
.pipe(gulp.dest(`${versionPath}/static/js/`))
}); // 替换${versionPath}/static/config/index-${env}.js window.SITE_CONFIG['version']配置变量
gulp.task('replace:version', ['create:versionCatalog'], function () {
return gulp.src(`${versionPath}/static/config/index-${env}.js`)
.pipe($.replace(/window.SITE_CONFIG\['version'\] = '.*'/g, `window.SITE_CONFIG['version'] = '${version}'`))
.pipe(gulp.dest(`${versionPath}/static/config/`))
}); // 合并${versionPath}/static/config/[index-${env}, init].js 至 ${distPath}/config/index.js
gulp.task('concat:config', ['replace:version'], function () {
return gulp.src([`${versionPath}/static/config/index-${env}.js`, `${versionPath}/static/config/init.js`])
.pipe($.concat('index.js'))
.pipe(gulp.dest(`${distPath}/config/`))
}); // 清空
gulp.task('clean', function () {
return del([versionPath])
}); gulp.task('default', ['clean'], function () {
// 获取环境配置
env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'prod'
// 开始打包编译
gulp.start(['build', 'create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config'], function () {
// 清除, 编译 / 处理项目中产生的文件
del([`${distPath}/static`, `${versionPath}/static/config`])
})
});

修改后的gulpfile.js

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var path = require('path');
var del = require('del'); var distPath = path.resolve('./dist');
var version = ''; // 版本号
var versionPath = ''; // 版本号路径
var env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'prod'; // 运行环境 // 创建版本号(年月日时分)
(function () {
var d = new Date();
var yy = d.getFullYear();
var MM = d.getMonth() + 1 >= 10 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1);
var DD = d.getDate() >= 10 ? d.getDate() : '0' + d.getDate();
var h = d.getHours() >= 10 ? d.getHours() : '0' + d.getHours();
var mm = d.getMinutes() >= 10 ? d.getMinutes() : '0' + d.getMinutes();
version = yy + MM + DD + h + mm;
versionPath = distPath + '/' + version;
})(); // 编译
gulp.task('build', $.shell.task([ 'node build/build.js' ])); // 创建版本号目录
gulp.task('create:versionCatalog', function () {
return gulp.src(`${distPath}/static/**/*`)
.pipe(gulp.dest(`${versionPath}/static/`))
}); // 替换${versionPath}/static/js/manifest.js window.SITE_CONFIG.cdnUrl占位变量
gulp.task('replace:cdnUrl', function () {
return gulp.src(`${versionPath}/static/js/manifest.js`)
.pipe($.replace(new RegExp(`"${require('./config').build.assetsPublicPath}"`, 'g'), 'window.SITE_CONFIG.cdnUrl + "/"'))
.pipe(gulp.dest(`${versionPath}/static/js/`))
}); // 替换${versionPath}/static/config/index-${env}.js window.SITE_CONFIG['version']配置变量
gulp.task('replace:version', function () {
return gulp.src(`${versionPath}/static/config/index-${env}.js`)
.pipe($.replace(/window.SITE_CONFIG\['version'\] = '.*'/g, `window.SITE_CONFIG['version'] = '${version}'`))
.pipe(gulp.dest(`${versionPath}/static/config/`))
}); // 合并${versionPath}/static/config/[index-${env}, init].js 至 ${distPath}/config/index.js
gulp.task('concat:config', function () {
return gulp.src([`${versionPath}/static/config/index-${env}.js`, `${versionPath}/static/config/init.js`])
.pipe($.concat('index.js'))
.pipe(gulp.dest(`${distPath}/config/`))
}); //清除, 编译 / 处理项目中产生的文件
gulp.task('cleanBuild', function () {
return del([`${distPath}/static`, `${versionPath}/static/config`])
});
// 清空
gulp.task('clean', function () {
return del([versionPath])
}); //gulp.series|4.0 依赖
//gulp.parallel|4.0 多个依赖嵌套
gulp.task('default',gulp.series(gulp.series('build','create:versionCatalog','replace:cdnUrl','replace:version','concat:config','cleanBuild')));

3.最后编译打包

1. npm run build
2. npm install -g serve
3. serve dist

到目前为止 编译打包成功!

win10遇到的一些问题

如果gulp -v显示报错

删除文件gulp.ps1文件:C:\Users\D\AppData\Roaming\npm\gulp.ps1

或用管理员身份打开:Windows Powershell ;

然后输入:

set-ExecutionPolicy RemoteSigned

策略选择:选择Y 或者A

转载指明出处:https://www.cnblogs.com/dennyLee2025/p/13686140.html

renren-fast-vue@1.2.2 项目编译报错: build `gulp`的更多相关文章

  1. 【vue】项目编译报错 Error: No PostCSS Config found in...

    问题描述: 项目在本地运行不报错,上传到 GitHub 之后,再 clone 到本地,执行: npm install 安装完成之后再执行: npm run dev 这时报错 Error: No Pos ...

  2. 安装asp.net mvc4后mvc3项目编译报错

    安装asp.net mvc4之后,之前的mvc3项目编译时报这个错“The type System.Web.Mvc.ModelClientValidationRule exists in both c ...

  3. maven项目编译报错处理

    1.问题一: [ERROR] Failed to execute goal on project data-common: Could not resolve dependencies for pro ...

  4. 【vue】项目编译报错‘npm ERR! **@**dev: `webpack-dev-server --inline --progress --config ’’

    关于npm ERR! **@**dev: `webpack-dev-server --inline --progress --config‘ 原因:这是新版webpack存在的BUG,卸载现有的新版本 ...

  5. maven项目编译报错:Type Dynamic Web Module 3.0 requires Java 1.6 or newer.

    在maven的pom.xml文件中增加: <build>   <plugins>     <plugin>         <groupId>org.a ...

  6. idea 编译报错 Build completed with 1 error and 0 warnings in 2 s 113 ms

    settings里java compiler改成正确版本 project structure里同样如此

  7. VUE编译报错 Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead

    背景: 在使用VUE添加标签的时候编译报错,报错如下: Component template should contain exactly one root element. If you are u ...

  8. nuxtjs在vue组件中使用window对象编译报错的解决方法

    我们知道nuxtjs是做服务端渲染的,他有很多声明周期是运行在服务端的,以及正常的vue声明周期mounted之前均是在服务端运行的,那么服务端是没有比如window对象的location.navag ...

  9. maven项目检出后报错(包括编译报错和运行报错)的常见检查处理方式

    maven项目检出后报错(包括编译报错和运行报错)的常见检查处理方式: 1.更改项目的jdk为我们安装的jdk2.更改build配置里的 output folder 目录为 xxx项目名/target ...

  10. 【maven】【IDEA】idea中使用maven编译项目,报错java: 错误: 找不到符号 【2】

    =================================================================================== idea中使用maven编译项目 ...

随机推荐

  1. [转帖]shell 使用sed或awk将文本中的上下两行合并为一行

    例如要装下面文本上下两行合并为一行 文件test内容: # cat test a1 ce ef 12 45 57 efef 5656 gfg 455 上下两行合并为一行: # sed -n '{N;s ...

  2. [转帖]DOCKER默认网段和主机网段冲突解决

    https://www.cnblogs.com/yinliang/p/13189334.html 一. docker默认网卡docker0 172.17.0.0可能会与主机冲突,这时候需要修改dock ...

  3. [转帖]金仓数据库KingbaseES表空间(tablespace)知多少

    金仓数据库KingbaseES表空间定义 金仓数据库KingbaseES中的表空间允许在文件系统里定义那些代表数据库对象的文件存放位置,比如表和索引等.一旦表空间被创建,那么就可以在创建数据库对象时通 ...

  4. 人大金仓学习之一_kwr的简单学习

    人大金仓学习之一_kwr的简单学习 摘要 周末在家想着学习一下数据库相关的内容. 网上找了不少资料, 想着直接在本地机器上面进行一下安装与验证 理论上linux上面应该更加简单. windows 上面 ...

  5. [转帖]CygWin、MingW、MSYS之间的关系

    https://www.jianshu.com/p/09198f6e0a3c 前言 在跨平台开发或移植中,经常会听说Cygwin.MingW.MSYS,他们之间是什么关系?对于将要完成的任务,应该选择 ...

  6. [转帖]一行Python代码实现同一局域网内的文件共享

    在不同的设备之间传输文件除了数据线,网盘传输外是否还有其他优雅的方法?我们可以使用一行Python代码使局域网内的所有设备都可以访问并下载文件夹内的文件. 要求: 电脑中安装配置好python 访问的 ...

  7. JVM内存学习 2.0

    先说一下结果 1. Linux的内存分配是惰性分配的. APP申明了 kernel并不会立即进行初始化和使用. 2. JVM的内存主要分为, 堆区, 非堆区, 以及jvm使用的其他内存. 比如直接内存 ...

  8. Oracle 高版本导出到低版本的测试验证

    今天验证Oracle 由高版本 备份恢复到低版本 与方神沟通(双 还是他) 说可以使用 version的参数..然后搞一下.. expdp system/Test6530@ora12cr2 schem ...

  9. 海量数据 vastbase G100 V2.2安装简单总结

    海量数据vastbase G100 V2.2 安装总结 背景说明 最近进行信创四期的数据库兼容性验证, 获取了海量数据的一个信创名录内的安装介质. 一直忙于出差, 今天晚上趁着冬至回家比较早在家里进行 ...

  10. 【原创】linux为什么不是实时操作系统

    一.什么是实时操作系统(RTOS)? 可参见本博客之前的文章: 什么是实时 实时的分类 常见的RTOS latency和jitter 总结一下,实时其实说的是系统响应事件需要的时间的确定性,时间必须确 ...