{"id":16763604,"url":"https://github.com/oti/gulp-imagemin-with-esm","last_synced_at":"2025-03-16T10:29:00.305Z","repository":{"id":39842267,"uuid":"457823370","full_name":"oti/gulp-imagemin-with-esm","owner":"oti","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-08T11:02:18.000Z","size":6835,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-22T22:32:25.247Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-10T14:54:46.000Z","updated_at":"2022-02-12T10:01:05.000Z","dependencies_parsed_at":"2022-09-09T08:40:14.565Z","dependency_job_id":null,"html_url":"https://github.com/oti/gulp-imagemin-with-esm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oti%2Fgulp-imagemin-with-esm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oti%2Fgulp-imagemin-with-esm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oti%2Fgulp-imagemin-with-esm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oti%2Fgulp-imagemin-with-esm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oti","download_url":"https://codeload.github.com/oti/gulp-imagemin-with-esm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243857225,"owners_count":20359155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T05:07:03.510Z","updated_at":"2025-03-16T10:29:00.255Z","avatar_url":"https://github.com/oti.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-imagemin with ESM\n\ngulp-imagemin v8.0.0 を ESM 環境下で利用する際の、エラー再現と解決策 3 つを提示するリポジトリ。\n\n## gulp を ESM 化したいオレたちは公式のアナウンスの元 gulpfile.esm.js を始めた\n\n[Transpilation - JavaScript and Gulpfiles | gulp](https://gulpjs.com/docs/en/getting-started/javascript-and-gulpfiles#transpilation)\n\n```zsh\nmv gulpfile.js gulpfile.esm.js\nnpm i -D esm gulp gulp-imagemin\n```\n\n```js\n// gulpfile.esm.js\nimport gulp from \"gulp\";\nimport { image } from \"./task/image.js\";\n\nexport default gulp.series(image);\n```\n\n```js\n// ./task/image.js\nimport gulp from \"gulp\";\nimport imagemin, { mozjpeg } from \"gulp-imagemin\";\n\nexport const image = () =\u003e\n  gulp\n    .src(\"./src/image/**/*\")\n    .pipe(imagemin([mozjpeg({ quality: 50 })]))\n    .pipe(gulp.dest(\"./dist/image/\"));\n```\n\nそして `npx gulp` を実行するとエラーに……。（ [`./error-reenactment/`](./error-reenactment/) ディレクトリで再現可能）\n\n## 解決方法\n\n1. gulp-imagemin を v7.1.0 にダウングレードする [`./use-gulp-imagemin-v7/`](./use-gulp-imagemin-v7/)\n2. package.json に `\"type\": \"module\"` を追加する [`./use-type-module/`](./use-type-module/)\n3. タスクファイルの拡張子を全て `.mjs` にする [`./use-mjs/`](./use-mjs)\n\n解決方法の詳細は各ディレクトリの README.md を参照してください。これらは gulp で ESM を使いたい人向けの方法です。\n\n「gulp は CommonJS 構文のままで gulp-imagmin を v8.0.0 にあげたらエラーが出たが、gulp を ESM にしたくない人」は、**gulp-imagemin を v8.0.0 にアップデートせず、v7.1.0 のまま使う以外に道はありません。**\n\nhttps://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n\u003e Stay on the existing version of the package until you can move to ESM.\n\n## No gulpfile found エラー\n\ngulp v4 で `.mjs` や `type: module` を利用したいのに `No fulpfile found` エラーになる場合があります。\n\nおそらく gulp-cli のバージョンが v2.3.0 になっていないと思われます。\n\n```zsh\nnpx gulp\n[16:05:46] No gulpfile found\n\nnpx gulp -v\nCLI version: 2.2.0 // \u003c= bad\nLocal version: 4.0.2\n```\n\npackage-lock.json を削除してから `npm i` を実行すると、gulp-cli もアップデートされます。\n\n```zsh\nrm -f package-lock.json\nnpm i\nnpx gulp -v\n\nCLI version: 2.3.0 // \u003c= good\nLocal version: 4.0.2\n```\n\nオッケー！\n\n---\n\nSpecial thanks [@watilde](https://github.com/watilde)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foti%2Fgulp-imagemin-with-esm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foti%2Fgulp-imagemin-with-esm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foti%2Fgulp-imagemin-with-esm/lists"}