赞
踩
- E:\gulp Project\hello-gulp>gulp
-
- Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: E:\gulp Project\hello-gulp\node_modules\gulp-imagemin\index.js
-
- require() of ES modules is not supported.
-
- require() of E:\gulp Project\hello-gulp\node_modules\gulp-imagemin\index.js from E:\gulp Project\hello-gulp\gulpfile.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "
- module" which defines all .js files in that package scope as ES modules.
-
- Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from E:\gulp Project\hello-gulp\node_modules\gulp-imagemin\package.json.
node将*.js
文件视为 CommonJS。而gulp-imagemin插件的package.json为 ES 模块。
相关文档package.json
和文件扩展名:
Modules: Packages | Node.js v17.0.1 Documentation
在 gulpfile.js 我改变了
const imagemin = require('gulp-imagemin');
到
const imagemin = import('gulp-imagemin')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。