Describe the bug
I'm in the process of updating gulpfile.js
from CommonJS to ESM, to support some updated plugins that come only in this format (mainly gulp-imagemin
).
The main change is related to the new import
syntax instead of require
: so, in example, const autoprefixer = require('gulp-autoprefixer');
is now import autoprefixer from 'gulp-autoprefixer';
.
The Gulpfile was renamed to gulpfile.esm.js
and I have installed the esm
NPM package, following the instructions on the Gulp docs.
The updated gulpfile is available here = https://github.com/stefanobartoletti/bricks/blob/gulp-esm/gulpfile.esm.js
After this conversion everything works well, all the tasks do what they are supposed to do, until I try to update gulp-imagemin
from v7.1.0
to v8.0.0
.
After trying to update it, the follwing errors appear after trying to run the scripts:
% yarn
yarn install v1.22.11
[1/4] ๐ Resolving packages...
success Already up-to-date.
$ gulp default
[15:17:01] Requiring external module esm
TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:34:9)
at eval (eval at <anonymous> (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/gulp-cli/lib/shared/require-or-import.js:10:15), <anonymous>:3:1)
at requireOrImport (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/gulp-cli/lib/shared/require-or-import.js:24:7)
at execute (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/gulp-cli/lib/versioned/^4.0.0/index.js:37:3)
at Liftoff.handleArguments (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/gulp-cli/index.js:211:24)
at Liftoff.execute (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/liftoff/index.js:201:12)
at module.exports (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/flagged-respawn/index.js:51:3)
at Liftoff.<anonymous> (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/liftoff/index.js:191:5)
at /Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/liftoff/index.js:149:9
at /Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/v8flags/index.js:162:14 {
code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
and
% yarn build
yarn run v1.22.11
$ gulp build
[15:20:53] Requiring external module esm
TypeError: Invalid host defined options
at eval (eval at <anonymous> (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/gulp-cli/lib/shared/require-or-import.js:10:15), <anonymous>:3:1)
at requireOrImport (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/gulp-cli/lib/shared/require-or-import.js:24:7)
at execute (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/gulp-cli/lib/versioned/^4.0.0/index.js:37:3)
at Liftoff.handleArguments (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/gulp-cli/index.js:211:24)
at Liftoff.execute (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/liftoff/index.js:201:12)
at module.exports (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/flagged-respawn/index.js:51:3)
at Liftoff.<anonymous> (/Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/liftoff/index.js:191:5)
at /Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/liftoff/index.js:149:9
at /Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/v8flags/index.js:162:14
at /Users/stefanobartoletti/Sviluppo/Personali/bricklayer/bricks/node_modules/v8flags/index.js:41:14
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Steps To Reproduce
- Clone this repository:
git clone https://github.com/stefanobartoletti/bricks.git
- Switch to
gulp-esm
branch, where the update of the Gulp configuration is developed: git checkout gulp-esm
- Install dependencies:
yarn
- Test tasks to confirm that everything goes fine:
yarn dev
, yarn build
, yarn watch
(no errors are expected until now).
- Upgrade
gulp-imagemin
to v8.0.0
: yarn upgrade --latest gulp-imagemin
- Run
yarn dev
, the previous errors appear, preventing the task to complete successfully.
Summary
After converting gulpfile to ESM, updating gulp-imagemin
to v8.0.0
generates some errors about
TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
TypeError: Invalid host defined options
Some help is welcome with this issue, as I am unable to figure out myself how to solve it.