I’m working on a Next.js project where I’m using both fabric.js and @imgly/background-removal-node. The @imgly/background-removal-node package depends on sharp for background removal functionality. My project works perfectly on the main branch where @imgly/background-removal-node alone is used. However, once I add fabric.js in a new branch, I start seeing errors related to sharp, specifically:
Something went wrong installing the "sharp" module
\?C:UsersUsernameDesktopmyprojectnode_modules@imglybackground-removal-nodenode_modulessharpbuildReleasesharp-win32-x64.node
Steps Taken:
Reinstalled sharp with npm install sharp.
Tried loading fabric.js dynamically to reduce conflicts.
Attempted various versions of fabric.js and sharp to check compatibility issues.
Despite these attempts, I keep getting sharp module errors as soon as fabric.js is installed. If I remove fabric.js, everything works again.
Environment:
Node.js version: 20.10.0
"next": "14.0.4",
"@types/fabric": "^5.3.0",
"fabric": "^5.3.0",
"@imgly/background-removal": "^1.4.5",
"@imgly/background-removal-node": "^1.4.5",
Question:
Has anyone encountered a similar conflict between fabric.js and sharp dependencies in Next.js? Are there any known compatibility issues or specific configurations required to get both fabric.js and @imgly/background-removal-node working together without causing sharp errors?
Any guidance or alternative approaches to prevent these conflicts would be greatly appreciated!