-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could not dynamically require "../src/build/Release/sharp-win32-x64.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs #3974
Comments
Oh, right! I tried using only Node and Sharp for image conversion, and the program was successful. The same code also runs successfully in a standalone Electron environment. The issue seems to arise only when using Vite with Electron. I suspect it might be related to configuration issues with esbuild or Rollup. I would appreciate your guidance on this. |
Did you see https://sharp.pixelplumbing.com/install#bundlers ? You may need to mark sharp as
https://github.com/rollup/plugins/tree/master/packages/commonjs#dynamicrequiretargets suggests the paths need to be relative to the directory that contains |
Hi, I'm running into the same problem. I am trying to package an Electron App (using Vue3, Vite, and electron-packager through Quasar framework) for Windows, from a Linux dev environment. I adapted the electron-builder configuration (asarUnpack) suggested in the doc for electron packager and I managed to have both nodes_modules/sharp and node_modules/@img outside the asar archive generated by electron.
The thing is that in the final build, the 'sharp-win32-x64.node' file is not located in one of the paths of the sharp.js file. (those mentionned by @guanzhongxu in the previous post). I managed to make it work by modifying directly the production code with the absolute path of 'sharp-win32-x64.node' file, but this is of course a terribly ugly workaround. (I also had to copy manually the win32 version next to the linux one but i guess this is another issue linked to npm and optional dependencies) Thank you for your help and this incredibly fast library 👏 |
Is Failing that a minimal, standalone repo that allows someone else to reproduce is the best next step. |
It is in the "dependencies". |
@3D-Bear If you need to support multiple platforms within the same installation tree then npm may (currently) be the wrong choice of package manager. Please try the |
Thanks for the updates. Downgrading to an unsupported version and hard-coding paths doesn't quite feel like the right approach. If you can create a repo that allows someone else to reproduce then I can try to help further. |
Thank you very much for your reply. If you don't mind, please take a look at my code when it's convenient for you. Currently, the code is still using version 0.32.5, and I manually modified the code for the screenshot part shown above. If you can address the issues with the latest version in Electron + Vite, feel free to modify my code. My computer is running on the Windows 10 operating system.If it's inconvenient for you, that's okay; you're already awesome! |
@guanzhongxu The problem you're facing is that electron-builder does not support pnpm symlinks - please see develar/app-builder#84 |
@lovell Thank you very much for your answer. |
@lovell I switched from npm to yarn (had to pay attention to explicitely install v3+ which isn't installed by default), and it is working fine. Just like you said I also had to add the I updated my repo with the solution if someone runs into the same issue. Thank you again for your help and this great lib ! |
I don't get it: why the issue was closed? It's been said that 'npm is not the best solution for cross-platform, use sth else', but it did work in a 0.32.x version of Sharp. It fails with the latest version and the recommended solution is not to use npm? Or to downgrade Sharp? |
I am developing an executable application using vite, Vue 3, and Electron. I need to use Sharp for image format conversion, but I encounter an error during startup. The error message is as follows:
Error: Could not load the "sharp" module using the win32-x64 runtime
What are you trying to achieve?
The code runs successfully.
Complete error message:
Error: Could not load the "sharp" module using the win32-x64 runtime
undefined: Could not dynamically require "../src/build/Release/sharp-win32-x64.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires opti
on of @rollup/plugin-commonjs appropriately for this require call to work.
undefined: Could not dynamically require "../src/build/Release/sharp-wasm32.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option
of @rollup/plugin-commonjs appropriately for this require call to work.
undefined: Could not dynamically require "@img/sharp-win32-x64/sharp.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rol
lup/plugin-commonjs appropriately for this require call to work.
undefined: Could not dynamically require "@img/sharp-wasm32/sharp.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup
/plugin-commonjs appropriately for this require call to work.
Possible solutions:
npm install --include=optional sharp
yarn add sharp --ignore-engines
See https://sharp.pixelplumbing.com/install#cross-platform
npm install --os=win32 --cpu=x64 sharp
See https://sharp.pixelplumbing.com/install
at Object. (D:\code\2024\2024.1\picture-conversion\dist-electron\main.js:4185:9)
at Module._compile (node:internal/modules/cjs/loader:1271:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
at Module.load (node:internal/modules/cjs/loader:1126:32)
at Module._load (node:internal/modules/cjs/loader:967:12)
at l._load (node:electron/js2c/asar_bundle:2:13642)
at ModuleWrap. (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
I have tried to resolve the issue.
npm install --include=optional sharp
npm install --os=win32 --cpu=x64 sharp
In the
vite.config.ts
file, I configured theesbuild
option as follows:However, none of these solutions worked.
The text was updated successfully, but these errors were encountered: