3

我正在尝试在 vue.js 中使用图像调整大小库 imagemin,但是在我安装 imagemin-mozjpeg 后它向我抛出了这个错误。我还没有开始使用它,只是导入它会引发错误。这是错误。

Uncaught TypeError: Cannot read property 'dirname' of undefined
    at eval (index.js?7f9a:4)
    at Object../node_modules/imagemin/node_modules/glob-parent/index.js (app.js:3705)
    at __webpack_require__ (app.js:727)
    at fn (app.js:101)
    at eval (pattern.js?7bc8:4)
    at Object../node_modules/imagemin/node_modules/fast-glob/out/utils/pattern.js (app.js:3669)
    at __webpack_require__ (app.js:727)
    at fn (app.js:101)
    at eval (index.js?61cd:11)
    at Object../node_modules/imagemin/node_modules/fast-glob/out/utils/index.js (app.js:3645)

这是我的包 json

"dependencies": {
    "bootstrap-vue": "^2.0.4",
    "firebase": "^7.2.3",
    "flatpickr": "^4.5.1",
    "imagemin": "^7.0.0",
    "imagemin-mozjpeg": "^8.0.0",
    "nouislider": "^11.1.0",
    "register-service-worker": "^1.5.2",
    "vue": "^2.6.6",
    "vue-flatpickr-component": "^8.1.1",
    "vue-lazyload": "^1.2.6",
    "vue-router": "^3.0.2",
    "vue2-transitions": "^0.2.3"
  },

这就是我在我的组件中导入它的方式

const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
4

0 回答 0