Closed AndreasFaust closed 1 year ago
Fixed it. The problem was, that my Strapi installation was a bit older. It was updated to 4.11.7
but not to Typescript. I had to use require
instead of import
in ./src/extensions/upload/strapi-server.ts
which was the problem. After updating Strapi to Typescript and using import
it worked.
Is there a way to fix this without using import
or switching to TypeScript? 😭
I'm using Strapi 4.21.1, the JS, not TS version. I get the same error.
src/extensions/upload/strapi-server.js
const imageOptimizerService = require("strapi-plugin-image-optimizer/dist/server/services/image-optimizer-service");
module.exports = (plugin) => {
plugin.services["image-manipulation"] = imageOptimizerService;
return plugin;
};
I don't plan on switching to the TS version of Strapi. Is there a way to use this image optimization plugin in the js version of Strapi?
PS: After some digging and debugging, I've figured out the cause of the problem:
const imageOptimizerService = require("strapi-plugin-image-optimizer/dist/server/services/image-optimizer-service").default;
module.exports = (plugin) => {
plugin.services["image-manipulation"] = imageOptimizerService;
return plugin;
};
Notice the .default at the end, when using require() It works now. Please add this to the docs ( "2. Extend Strapi's upload plugin" section ), in case others might bump into the same issue when figuring out how to import/require in the JS version of Strapi.
Thanks!
Thank you for creating this module! Unfortunately I cannot get it to run. Following your instructions I end up receiving this error as soon as I try to upload an image:
Strapi’s
upload
-Service tries to importisImage
fromplugin.services["image-manipulation"]
, but fails because it gets overridden by this plugin’s service, which does not containisImage
.