Closed stefanobartoletti closed 3 years ago
I was able to solve this by reverting gulpfile.esm.js
to gulpfile.js
, and declaring "type": "module"
inside package.json
.
same problem i am facing but couldn't find any solution...don't know how i can fix it.
Hi, If you need help please open a new issue with a detailed description, so we can sort it out
I was able to solve this by reverting
gulpfile.esm.js
togulpfile.js
, and declaring"type": "module"
insidepackage.json
.
When I do this simple change, I get the following errors showing up instead:
% npm run test
> gulp test
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/XXXXXX/_work/_git/PROJECT/gulpfile.js' is not supported resolving ES modules imported from /Users/XXXXXX/_work/_git/PROJECT/node_modules/gulp-cli/lib/shared/require-or-import.js
Did you mean to import /Users/XXXXXX/_work/_git/PROJECT/gulpfile.js/index.js?
at new NodeError (internal/errors.js:322:7)
at finalizeResolution (internal/modules/esm/resolve.js:314:17)
at moduleResolve (internal/modules/esm/resolve.js:776:10)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:887:11)
at Loader.resolve (internal/modules/esm/loader.js:89:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
at Loader.import (internal/modules/esm/loader.js:177:28)
at importModuleDynamically (internal/modules/cjs/loader.js:1028:27)
at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
at eval (eval at <anonymous> (/Users/XXXXXX/_work/_git/PROJECT/node_modules/gulp-cli/lib/shared/require-or-import.js:10:15), <anonymous>:3:1) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///Users/XXXXXX/_work/_git/PROJECT/_git/chase_abe_education/gulpfile.js'
}
Any ideas what might be causing this error?
I'm also using the code splitting technique for the gulpfile.esm.js
file: gulpfile.esm.js/index.js
Here's my sample index.js
file to test (inside the gulpfile.js
folderβfollowing your example to rename it):
import gulp from "gulp";
import rimraf from "rimraf";
export const test = gulp
.series((done) => {
rimraf("./dist", done);
})(done);
I got my setup working finally. It must have been a cache issue? π€·π»
project/
gulpfile.esm.js/
index.js
package.json
{
"name": "gulp-esm",
"version": "1.0.0",
"description": "",
"private": true,
"author": "Billy Romano",
"license": "MIT",
"scripts": {
"start": "gulp",
"test": "gulp test"
},
"dependencies": {
"@popperjs/core": "^2.11.5",
"bootstrap": "^5.0.1",
"bootstrap-tagsinput": "^0.7.1",
"bootstrap5-tags": "^1.4.34",
"jquery": "^3.6.0",
"jquery-ui": "^1.13.0",
"jquery.easing": "^1.4.1",
},
"devDependencies": {
"@babel/core": "^7.17.10",
"@babel/plugin-proposal-throw-expressions": "^7.14.5",
"@babel/preset-env": "^7.17.10",
"@babel/register": "^7.17.7",
"babel-loader": "^8.2.5",
"core-js": "^3.22.4",
"esm": "^3.2.25",
"expose-loader": "^3.1.0",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-buffer": "^0.0.2",
"gulp-cli": "^2.0.1",
"gulp-htmlmin": "^5.0.1",
"gulp-imagemin": "^8.0.0",
"gulp-load-plugins": "^2.0.7",
"gulp-postcss": "^9.0.0",
"gulp-sass": "^5.1.0",
"gulp-sourcemaps": "^3.0.0",
"rimraf": "^3.0.2",
"sass": "^1.51.0",
"through2": "^4.0.2",
"vinyl-named": "^1.1.0",
"webpack": "^5.72.0",
"webpack-stream": "^7.0.0",
"yargs": "^17.4.1"
}
}
import gulp from "gulp";
import rimraf from "rimraf";
export const test = gulp
.series((done) => {
rimraf("./dist", done);
});
% npm run test
> gulp-esm@1.0.0 test
> gulp test
[10:04:54] Requiring external module esm
[10:04:55] Using gulpfile ~/_work/_git/PROJECT/gulpfile.esm.js
[10:04:55] Starting 'test'...
[10:04:55] Starting '<anonymous>'...
[10:04:55] Finished '<anonymous>' after 177 ms
[10:04:55] Finished 'test' after 179 ms
chalk
for displaying log messages with color, make sure to use v4 only
npm i -D chalk@4
chalk
v5 with Gulp will show this error: TypeError: Invalid host defined options
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 (mainlygulp-imagemin
). The main change is related to the newimport
syntax instead ofrequire
: so, in example,const autoprefixer = require('gulp-autoprefixer');
is nowimport autoprefixer from 'gulp-autoprefixer';
.The Gulpfile was renamed to
gulpfile.esm.js
and I have installed theesm
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
fromv7.1.0
tov8.0.0
.After trying to update it, the follwing errors appear after trying to run the scripts:
and
Steps To Reproduce
git clone https://github.com/stefanobartoletti/bricks.git
gulp-esm
branch, where the update of the Gulp configuration is developed:git checkout gulp-esm
yarn
yarn dev
,yarn build
,yarn watch
(no errors are expected until now).gulp-imagemin
tov8.0.0
:yarn upgrade --latest gulp-imagemin
yarn dev
, the previous errors appear, preventing the task to complete successfully.Summary
After converting gulpfile to ESM, updating
gulp-imagemin
tov8.0.0
generates some errors aboutTypeError [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.