Nuxt v3 with Nitro worker threads - Module did not self-register
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
- [x] Running
npm install sharpcompletes without error. - [x] Running
node -e "require('sharp')"completes without error.
If you cannot confirm both of these, please open an installation issue instead.
Are you using the latest version of sharp?
- [x] I am using the latest version of
sharpas reported bynpm view sharp dist-tags.latest.
If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.
What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?
System:
OS: macOS 12.3.1
CPU: (10) x64 Apple M1 Pro
Memory: 21.15 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.19.0 - ~/.nvm/versions/node/v14.19.0/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 8.14.0 - ~/.nvm/versions/node/v14.19.0/bin/npm
What are the steps to reproduce?
Install sharp package from Nuxt 3 RC5 and import * as sharp from "sharp";
I have even tried to install using --platform and --arch but still not working.
What is the expected behaviour?
not available
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
not available
Please provide sample image(s) that help explain this problem
Please see https://sharp.pixelplumbing.com/install#worker-threads
Hi @lovell thanks for the prompt response.
Btw, how do I tell my Nuxt 3 on this Worker Thread ?
Perhaps you could create a minimal repo that allows someone else to reproduce.
Found this thread https://github.com/lovell/sharp/issues/2981
It seems not working on Nuxt 3?
#2981 relates to the creation of an ESM wrapper for sharp; mention of Nuxt is coincidental.
#2981 relates to the creation of an ESM wrapper for sharp; mention of Nuxt is coincidental.
Sorry, I'm still don't get it 🥹 Is it really Nuxt 3 can't use Sharp yet?
Please create a minimal repo that allows someone else to reproduce, then we can start to answer your questions.
Here's the link https://stackblitz.com/edit/nuxt-starter-hw78au?file=server%2Fapi%2Fsharp.ts
run npm run dev and you will encounter the error.
Thank you. Although Stackblitz doesn't work, I was able to download the project and run it locally to reproduce.
Remembering that https://sharp.pixelplumbing.com/install#worker-threads says:
the main thread must call require('sharp') before worker threads are created.
I can see that Nuxt uses Nitro for its local dev server, which uses worker threads.
https://github.com/unjs/nitro/blob/main/src/dev/server.ts
The Nitro docs state that it provides hooks that allow you to inject custom lifecycle logic.
https://nitro.unjs.io/config/#hooks
Putting all this together, the following appears to work:
export default defineNuxtConfig({
nitro: {
hooks: {
'dev:reload': () => require('sharp')
}
}
})
As an aside, the Cannot call a namespace ('sharp') warnings can be silenced with the following change:
- import * as sharp from 'sharp';
+ import sharp from 'sharp';
Thanks Lovell, I was able to run following your method. Unfortunately sharp doesn't accept ArrayBuffer. Will dig further on this.

@juno-w Were you able to make progress with this?
@juno-w Were you able to make progress with this?
Hi @lovell , the buffer() is not working though. I will close this issue and reopen it once I get more details on this.