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

module.parent deprecated in Node 14+ #141

Closed
DaveyJake opened this issue Sep 15, 2021 · 10 comments
Closed

module.parent deprecated in Node 14+ #141

DaveyJake opened this issue Sep 15, 2021 · 10 comments

Comments

@DaveyJake
Copy link

Describe the bug
As of Node v14.6.0, module.parent is deprecated.

To Reproduce
Steps to reproduce the behavior:

  1. Attempting to use the plugin in my gulpfile.babel.js produces the following error:

TypeError: Cannot read property 'filename' of undefined at at Object. (/path/to/node_modules/gulp-load-plugins/index.js:170:46)

Expected behavior
I expect my node environment to startup like it always has.

Desktop (please complete the following information):

  • OS: MacOS Big Sur 11.5.2
  • Browser: Google Chrome
  • Version: 93.0.4577.63

Temporary Fix
I've removed the parentDir variable from index.js and placed the path.dirname(module.parent.filename) value inside the config variable on line 47. It now looks like this:

const config = options.config || findup('package.json', { cwd: path.dirname(module.parent.filename) });

I now initialize the plugin inside my gulpfile.babel.js like this:

import plugins from 'gulp-load-plugins';

const $ = plugins({ config: path.resolve( __dirname, 'package.json' ) });
@strarsis
Copy link

strarsis commented Sep 25, 2021

@jackfranklin:
+1, this is a blocker for all recent node versions! 😿

davTypeError: Cannot read property 'filename' of undefined
const parentDir = path.dirname(module.parent.filename);

module.parent: https://nodejs.org/api/modules.html#modules_module_parent
Deprecated since: v14.6.0, v12.19.0

@jameelmoses
Copy link
Collaborator

I’m on vacation right now, but I’ll take a look at this next week. In the meantime, happy to review a PR if you’re inclined.

@romanalesenkov1
Copy link

any updates on the issue?

@jameelmoses
Copy link
Collaborator

I'm unable to replicate this issue on Node 14.18. Can you provide a repo that I'm able to replicate please?

How are you trying to instantiate the plugin? Can you try const $ = require('gulp-load-plugins')();?

@daedam
Copy link

daedam commented Apr 6, 2022

I encountered this problem today as well, while trying to convert my gulpfile to use ESM. I am using the following in gulpfile.mjs to instantiate the plugin:

import gulpLoadPlugins from 'gulp-load-plugins';
const $ = gulpLoadPlugins();

I am running Node.js 16.14.2.

@jameelmoses
Copy link
Collaborator

Happy to look into this if someone can create a repo with a reproducible issue. I'm using Node v16.14.0 right now with gulpfile.babel.js without issue.

@jameelmoses
Copy link
Collaborator

can you try this instead of the multi-line statement?

const $ = require('gulp-load-plugins')();

@daedam
Copy link

daedam commented Apr 7, 2022

Happy to look into this if someone can create a repo with a reproducible issue. I'm using Node v16.14.0 right now with gulpfile.babel.js without issue.

I created this repo to demonstrate the situation with using Gulp as an ECMAScript module (ESM). The main branch demonstrates the error using ESM syntax with import ... from. The commonjs branch is the working version using CommonJS with require().

@SCPCOEXR
Copy link

SCPCOEXR commented May 10, 2022

Also dealing with the issue @daedam mentioned.
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\project\node_modules\gulp-imagemin\index.js from C:\project\node_modules\gulp-load-plugins\index.js not supported.
Instead change the require of C:\project\node_modules\gulp-imagemin\index.js in C:\project\node_modules\gulp-load-plugins\index.js to a dynamic import() which is available in all CommonJS modules.

Using your suggestion @jameelmoses of:
const $ = require('gulp-load-plugins')();

In my gulpfile.babel.js:
function images() { return gulp.src('src/assets/img/**/*') .pipe($.if(PRODUCTION, $.imagemin([ $.imagemin.jpegtran({ progressive: true }), ]))) .pipe(gulp.dest(PATHS.dist + '/assets/img')); }

@jameelmoses
Copy link
Collaborator

This has been resolved in v2.0.8

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

6 participants