Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help: How to use vinyl-paths in gulpfile.js to avoid [ERR_REQUIRE_ESM]? #12

Closed
SamuelMiller opened this issue May 13, 2022 · 1 comment

Comments

@SamuelMiller
Copy link

SamuelMiller commented May 13, 2022

I am getting "Error [ERR_REQUIRE_ESM]: require() of ES Module" error when I do the following in my gulpfile.js, following older tutorials online:

const gulp =
    { src, dest, watch, series, parallel } = require('gulp'),
    $ = require('gulp-load-plugins')({ camelize: true, lazy: true }),
    del = require('del'),
    vinylPaths = require('vinyl-paths')
};

function convertCase() {
    return src(['./src/assets/fonts/playtime/*.ttf'])
        .pipe(vinylPaths(del))
        .pipe($.rename(function (path) {
            path.dirname = path.dirname.toLowerCase(); path.basename = path.basename.toLowerCase(); path.extname = path.extname.toLowerCase();
        }))
        .pipe(dest('./src/assets/fonts'))
};

I suspect the error is occurring because vinyl paths is now an ESM module. Reading online, I seem to have three options:

Switch the project to an ESM module, dynamically import an ESM module into a CommonJS module using let, await, import, or use an older version of the plugin. Besides downgrading the vinyl-plugin , I am using, I have absolutely no idea how to do the other options--what does using an ESM module look like in gulpfile.js? Is there a way, I can use vinyl-paths using a somewhat similar format to the above, so I can use my other gulp plugins in my gulpfile.js?

@sindresorhus
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants