How do I create and use a clean task in Gulp version 5?

  Kiến thức lập trình

I’m trying to create a clean task in my gulpfile that currently looks like this:

const { series, src, dest } = require('gulp');
const del = import('del');

function clean() {

function copy(cb) {
    src('node_modules/bootstrap/dist/css/*').pipe(dest('wwwroot/lib/bootstrap/dist/css', { overwrite: true }));
    src('node_modules/bootstrap/dist/js/*').pipe(dest('wwwroot/lib/bootstrap/dist/js', { overwrite: true }))
} = copy;
exports.clean = clean;
exports.default = series(clean, copy);

When I run gulp I get this:

PS C:projectsMtcsw> gulp
[08:42:56] Using gulpfile C:projectsMtcswgulpfile.js
[08:42:56] Starting 'default'...
[08:42:56] Starting 'clean'...
[08:42:56] 'clean' errored after 952 μs
[08:42:56] TypeError: del is not a function
    at clean (C:projectsMtcswgulpfile.js:6:5)
    at bound (node:domain:432:15)
    at runBound (node:domain:443:12)
    at asyncRunner (C:projectsMtcswnode_modulesasync-doneindex.js:52:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
[08:42:56] 'default' errored after 3.92 ms

Earlier instead of import(‘del’) I had require(‘del’) and was getting this:

PS C:projectsMtcsw> gulp
Error [ERR_REQUIRE_ESM]: require() of ES Module C:projectsMtcswnode_modulesdelindex.js from C:projectsMtcswgulpfile.js not supported.
Instead change the require of index.js in C:projectsMtcswgulpfile.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (C:projectsMtcswgulpfile.js:3:13) {

For reference, the devDependencies of my package.json looks like this:

    "bootstrap": "5.3.3",
    "eslint": "^9.2.0",
    "gulp": "5.0.0",
    "del": "7.1.0"

What’s odd to me is that when I look at the example in I was doing what they had shown. So I’m trying to follow the instructions, but clearly missing something. What do I need to change?