我之所以来找你,是因为几天来我一直没有解决问题的方法。
版本:CLI版本:2.3.0 本地版本:3.9.1
节点:v12.18.4
当我启动命令yarn run dev(或简化gulp dev)时,我的任务是dev,参数问题,我之前的dev意识到了这段代码:
const path = require('path');
// Filters out non .js files. Prevents
// accidental inclusion of possible hidden files
export default function(name) {
return /(\.(js)$)/i.test(path.extname(name));
};
这是下面的错误:
yarn run v1.22.5
$ cross-env BABEL_DISABLE_CACHE=1 NODE_ENV=development ./node_modules/.bin/gulp dev
[12:04:55] Requiring external module @babel/register
/Users/nicolas/vanam_dev/frontend/gulp/util/scriptFilter.js:5
export default function (name) {
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Module._compile (/Users/nicolas/vanam_dev/frontend/node_modules/pirates/lib/index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Object.newLoader [as .js] (/Users/nicolas/vanam_dev/frontend/node_modules/pirates/lib/index.js:104:7)
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)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/nicolas/vanam_dev/frontend/gulp/index.js:3:19)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
预先感谢您,希望您能够为我解锁。
答案 0 :(得分:0)
您正在使用ES6语法。
尝试使用node.js
函数return_name(名称){
return /(\.(js)$)/i.test(path.extname(name));
}
module.exports = { return_name }
答案 1 :(得分:0)
在使用Node v.12时,您不能仅使用导出和导入(这是ES6或Javascript 6的一部分),而不必将代码转换为ES5(可用于节点)。您可以使用babel来转换代码或修改调用节点以启动程序的方式。可以找到here
如果您是负责现有项目的新开发人员,那么肯定已经可以使用一种解决方法。
答案 2 :(得分:0)
Subhadip非常感谢您的使用,在我的yarn run dev之后出现了一个新错误:
yarn run v1.22.5
$ cross-env BABEL_DISABLE_CACHE=1 NODE_ENV=development ./node_modules/.bin/gulp dev
[14:07:09] Requiring external module @babel/register
/Users/nicolas/vanam_dev/frontend/gulp/index.js:7
const tasks = fs.readdirSync('./gulp/tasks/').filter(onlyScripts); // Ensure process ends after all Gulp tasks are finished
^
TypeError: #<Object> is not a function
at Array.filter (<anonymous>)
at Object.<anonymous> (/Users/nicolas/vanam_dev/frontend/gulp/index.js:5:47)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Module._compile (/Users/nicolas/vanam_dev/frontend/node_modules/pirates/lib/index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Object.newLoader [as .js] (/Users/nicolas/vanam_dev/frontend/node_modules/pirates/lib/index.js:104:7)
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)
at require (internal/modules/cjs/helpers.js:72:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
我的代码在此行:
const fs = require('fs');
const gulp = require('gulp');
var onlyScripts = require('./util/scriptFilter');
const tasks = fs.readdirSync('./gulp/tasks/').filter(onlyScripts);
// Ensure process ends after all Gulp tasks are finished
gulp.on('stop', function () {
if ( !global.isWatching ) {
process.nextTick(function () {
process.exit(0);
});
}
});
tasks.forEach((task) => {
require('./tasks/' + task);
});
为我的任务开发人员编写代码:
import gulp from 'gulp';
import runSequence from 'run-sequence';
gulp.task('dev', ['clean'], function(cb) {
global.isProd = false;
runSequence(['styles','vendors', 'fonts', 'views'], 'browserify', 'watch', cb);
// runSequence(['styles','vendors', 'images', 'fonts', 'views'], 'browserify', 'watch', cb);
});