react-image-file-resizer icon indicating copy to clipboard operation
react-image-file-resizer copied to clipboard

imageFileResizer not a function after building with Vite

Open ivanros opened this issue 3 years ago • 14 comments

Describe the bug Using Vitejs this is the only library that is unable to compile correctly in production. I understand that it is related to the way of compiling the library because if I copy and paste the code in my repository I get the Resizer to compile correctly. Uncaught (in promise) TypeError: er.imageFileResizer is not a function It may have related with the construction of the project in CommonJS.

To Reproduce Steps to reproduce the behavior: Build project with Vitejs.

Expected behavior Well, it would be awesome if it would just work. :)

Desktop (please complete the following information): OS: Ubuntu 20.04 Browser Chrome Edge

This is basically the same problem that this user had in issue https://github.com/onurzorluer/react-image-file-resizer/issues/60

ivanros avatar Feb 16 '22 08:02 ivanros

Related issue reported to vitejs https://github.com/vitejs/vite/issues/4935, looks like the commonjs2 build target is not compatible with the default vite config.

kanru avatar Mar 08 '22 14:03 kanru

Was anyone able to use this library with vite somehow? dying to know..

ksi9302 avatar Jul 12 '22 09:07 ksi9302

I got the same error , someone fixed this?

gzimbron avatar Aug 04 '22 12:08 gzimbron

Same problem. Vite 3.0

ysageev avatar Aug 10 '22 14:08 ysageev

vite 3.0.9 still same issue :(

tomichGIT avatar Aug 23 '22 18:08 tomichGIT

same issue

w6fux5 avatar Sep 19 '22 11:09 w6fux5

Same issue

mperezguendulain avatar Dec 05 '22 20:12 mperezguendulain

same issue

tkejr avatar Dec 14 '22 20:12 tkejr

Alright I figured out a solution

  1. First thing go here and copy the whole file https://github.com/onurzorluer/react-image-file-resizer/blob/3a0fab44211f985aaf048b4fa71027b7149da90e/src/index.js
  2. Make a file called Resizer.js in your src directory in react.
  3. Paste the code you copied in this file
  4. Whenever you want to use this function import Resizer from "relative path to Resizer.js";
  5. Remove import Resizer from "react-image-file-resizer"; wherever it is used

tkejr avatar Dec 17 '22 11:12 tkejr

This is not really helpful. I don't want to locally fork the module

My workaround is to do

import Resizer from "react-image-file-resizer";
// @ts-expect-error https://github.com/onurzorluer/react-image-file-resizer/issues/68
const resizer: typeof Resizer = (Resizer.default || Resizer);

DayBr3ak avatar Jan 23 '23 15:01 DayBr3ak

any updates on this?

mikejackowski avatar Jan 30 '23 09:01 mikejackowski

same issue

FauricioValencia avatar Feb 07 '23 04:02 FauricioValencia

same issue typeError: buildExports.imageFileResizer is not a function at onChange

nattapatpon avatar Apr 26 '23 02:04 nattapatpon

Alright I figured out a solution

  1. First thing go here and copy the whole file https://github.com/onurzorluer/react-image-file-resizer/blob/3a0fab44211f985aaf048b4fa71027b7149da90e/src/index.js
  2. Make a file called Resizer.js in your src directory in react.
  3. Paste the code you copied in this file
  4. Whenever you want to use this function import Resizer from "relative path to Resizer.js";
  5. Remove import Resizer from "react-image-file-resizer"; wherever it is used

it works , thanks for your help

Sachin249 avatar Sep 08 '23 13:09 Sachin249

Alright I figured out a solution

  1. First thing go here and copy the whole file https://github.com/onurzorluer/react-image-file-resizer/blob/3a0fab44211f985aaf048b4fa71027b7149da90e/src/index.js
  2. Make a file called Resizer.js in your src directory in react.
  3. Paste the code you copied in this file
  4. Whenever you want to use this function import Resizer from "relative path to Resizer.js";
  5. Remove import Resizer from "react-image-file-resizer"; wherever it is used

It worked.. thanks :)

shahidmau avatar Feb 04 '24 06:02 shahidmau