0

I come to you because for days I haven't had the solution to my problem.

Version: CLI version: 2.3.0 Local version: 3.9.1

Node: v12.18.4

When I launch my command yarn run dev (or to make simpler gulp dev) so my task is dev, well parameter I have a problem, the dev before me realized this code:

    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));

};

And here is the error which follows:

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.

Thank you in advance, I hope you will be able to unlock me.

3 Answers3

0

You are using ES6 Syntax.

Try this for node.js

function return_name (name){ return /(\.(js)$)/i.test(path.extname(name)); }

module.exports = { return_name }

0

As you are using Node v.12 you can not just use export and import (this is part of ES6 or Javascript 6) without taking care of transpiling your code to ES5 (usable by node). You can use babel to transpile your code or modify the way you call node to launch your program. The way to do this can be found here

If you are a new developer in charge of a preexisting project there is certainly a workaround already available to you.

clanglai
  • 149
  • 1
  • 6
0

Subhadip thank you very much it works, I have a new error after my 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.

My code where have this line:

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);
});

And code for my task dev:

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);

});