sindresorhus / del

Delete files and directories
MIT License
1.33k stars 66 forks source link

Build fail when using Babel #146

Closed kirvedx closed 2 years ago

kirvedx commented 2 years ago

Issue

After upgrading to del v7, there is an error in the build.

What I did

I ran npx npm-check-updates -u and the result was:

Upgrading /home/rik/workspaces/kwaeri/node-kit/filesystem/package.json
[====================] 23/23 100%

 @babel/cli                                  ^7.17.6  →  ^7.18.9
 @babel/core                                 ^7.17.5  →  ^7.18.9
 @babel/plugin-proposal-object-rest-spread   ^7.17.3  →  ^7.18.9
 @babel/plugin-proposal-optional-chaining    ^7.16.7  →  ^7.18.9
 @babel/preset-env                          ^7.16.11  →  ^7.18.9
 @babel/register                             ^7.17.0  →  ^7.18.9
 @types/mocha                                 ^9.1.0  →   ^9.1.1
 @types/node                                ^17.0.20  →  ^18.0.6
 del                                          ^6.0.0  →   ^7.0.0
 mocha                                        ^9.2.1  →  ^10.0.0
 typescript                                   ^4.5.5  →   ^4.7.4

Run npm install to install new versions.

I then did subsequently run npm install

The Error

After running npm run build && npm run test, I received the following:

```bash
> gulp clean && gulp

[14:32:27] Requiring external module @babel/register
/home/rik/workspaces/kwaeri/node-kit/filesystem/gulpfile.babel.js:141
    }
      ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/rik/workspaces/kwaeri/node-kit/filesystem/node_modules/del/index.js from /home/rik/workspaces/kwaeri/node-kit/filesystem/gulpfile.babel.js not supported.
Instead change the require of index.js in /home/rik/workspaces/kwaeri/node-kit/filesystem/gulpfile.babel.js to a dynamic import() which is available in all CommonJS modules.

The problem

The suggestion says I should change require of ES Module to an Import. However, this is already the case. See my Gulpfile:

import del from 'del';

I use Babel for ES6 support. So, I've named my file gulpfile.babel.js, and I have a .babelrc file in the root of the project with the following contents:

{
    "presets": ["@babel/preset-env"],
    "env":
    {
        "test":
        {
            "plugins":
            [
                ["istanbul"],
                ["@babel/plugin-proposal-object-rest-spread"]
            ]
        },
        "development":
        {
            "plugins":
            [
                ["istanbul"],
                ["@babel/plugin-proposal-object-rest-spread"]
            ]
        }
    }
}

Other Information

I'm current running:

Environment:

I have NODE_OPTIONS=--no-experimental-fetch setup when terminal program is "vscode" within my .bashrc ⇨ simply because Node v18 brought some changes that require that for most of my modules.

Current Resolution

I've reverted to del v6

"del": "^6.0.0"

Conclusion

I'd like to know if this is something I'm failing to attend in some other fashion - or if this is an issue with the latest release (v7).

sindresorhus commented 2 years ago

This package is now pure ESM. Please read this. - https://github.com/sindresorhus/del/releases/tag/v7.0.0

jpike88 commented 2 years ago

@kirvedx just use rimraf instead, it will do the same job and you won't be subject to this weird ESM crusade.

kirvedx commented 2 years ago

@jpike88 Appreciate the mention - Thanks.

I mindlessly - and lazily - reported Del wasn't working with Gulp and continued working without updating it. I'm working with a collection of 40+ modules and really just wanted to avoid deviating into module template management at the time; but I've since done so.