Skip to content
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

Unable to find napi_register_module_v1 on mac m1 #20071

Open
VelinGeorgiev opened this issue Aug 5, 2023 · 15 comments
Open

Unable to find napi_register_module_v1 on mac m1 #20071

VelinGeorgiev opened this issue Aug 5, 2023 · 15 comments
Labels
bug Something isn't working node compat node native extension related to the node-api (.node)

Comments

@VelinGeorgiev
Copy link

I am having a hard time installing sharp npm module with Deno. I am currently using Deno 1.36 and mac m1 chip, also following the steps from sharp lovell/sharp#2583, but I am getting the error below.

error: Uncaught Error: 
Something went wrong installing the "sharp" module

Unable to find napi_register_module_v1 symbol in /Users/velingeorgiev/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.32.4/build/Release/sharp-darwin-arm64v8.node

Possible solutions:
- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
- Install for the current darwin-arm64v8 runtime: "npm install --platform=darwin --arch=arm64v8 sharp"
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (file:///Users/velingeorgiev/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.32.4/lib/sharp.js:37:9)
    at Object.<anonymous> (file:///Users/velingeorgiev/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.32.4/lib/sharp.js:40:4)
    at Module._compile (node:module:731:36)
    at Object.Module._extensions..js (node:module:745:12)
    at Module.load (node:module:656:34)
    at Function.Module._load (node:module:539:16)
    at Module.require (node:module:675:23)
    at require (node:module:789:20)
    at Object.<anonymous> (file:///Users/velingeorgiev/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.32.4/lib/constructor.js:11:1)
    at Object.<anonymous> (file:///Users/velingeorgiev/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.32.4/lib/constructor.js:441:4)
Watcher Process failed. Restarting on file change...

Is this by design, or will future support be provided?

@bartlomieju bartlomieju added bug Something isn't working node compat node native extension related to the node-api (.node) labels Aug 6, 2023
@bartlomieju
Copy link
Member

We want to have sharp working on Deno, it's surprising this error is raised. We need to check what mechanism sharp uses to register its native addon.

@VelinGeorgiev
Copy link
Author

VelinGeorgiev commented Aug 7, 2023

@bartlomieju , lovell might be able to help here.

@bartlomieju
Copy link
Member

Thanks, I'll try to dig into this problem this week.

@birkskyum
Copy link
Contributor

birkskyum commented Aug 23, 2023

There is some related info here:

@birkskyum
Copy link
Contributor

birkskyum commented Aug 24, 2023

@bartlomieju , there is a build of a wasm version here, which is more portable but a bit slower in case of simd (see Chart in ticket description) - it's still much better than nothing. This build is not on npm, so it's suggested to install from github repo. Can I perform the same trick with deno somehow, since this url is not an esm.sh or similar?

@birkskyum
Copy link
Contributor

birkskyum commented Aug 26, 2023

Regarding the strong focus on security of Deno, the approach taken here by Bun to introduce a list of trustedDependencies, instead of postinstall npm lifecycle script etc. because it's mentioned to be safer than allowing arbitrary scripts

@bartlomieju
Copy link
Member

Hey @VelinGeorgiev, @littledivy and I just did some digging into this issue. We used Deno v1.36.3 and this script:

import sharp from "npm:sharp";

const semiTransparentRedPng = await sharp({
  create: {
    width: 48,
    height: 48,
    channels: 4,
    background: { r: 255, g: 0, b: 0, alpha: 0.5 }
  }
})
  .png()
  .toBuffer();

Deno.writeFileSync("semi-transparent-red.png", semiTransparentRedPng);

The only problem we encountered was missing .node file (which appears is not distributed by sharp, but instead relies on the install script in the sharp's package.json file). Once we manually run that installscript (eg. by usingnpm run installin the./node_modules/sharp/` directory) it worked without a problem and wrote a PNG file with a red square.

Could you provide a full reproduction on how you arrived at that error? As it stands out it appears to me that the problem is that Deno doesn't support "lifecycle" hooks as pointed out by @birkskyum. This is something we've discussed several times and haven't arrived at a good solution yet.

@birkskyum
Copy link
Contributor

there are > 3 mil. weekly downloads of sharp, almost on par with something like next.js, so this would make a very big different in terms of node compat.

https://npmtrends.com/next-vs-sharp

@VelinGeorgiev
Copy link
Author

@bartlomieju I will give it a try with v1.36.3 and see if that will resolve the issue.

@birkskyum
Copy link
Contributor

birkskyum commented Sep 12, 2023

Could a list of "trustedDependencies" in deno.json and package.json similar to what bun introduced be a solution for deno as well, or are there other ideas? maybe cli flags or a special syntax in import statement? It would be great as a start to at have the deno run -A allow the execution of these scripts, no questions asked, if the convention is to configure permissions in the cli.

@lovell
Copy link

lovell commented Dec 1, 2023

For those who haven't yet seen, the latest sharp v0.33.0 now provides full support for Deno.

@brc-dd
Copy link

brc-dd commented May 28, 2024

Also getting this error when using @parcel/watcher. But it only happens when I run deno in watch mode. Minimal example:

// foo.ts

import watcher from 'npm:@parcel/watcher'

await watcher.subscribe(Deno.cwd(), (_, events) => {
  console.log(events)
})

setTimeout(() => {}, 60_000)
deno run --allow-read --allow-ffi --watch foo.ts

Try changing, saving the foo.ts file. Logs error:

error: Uncaught (in promise) TypeError: Unable to find napi_register_module_v1 symbol in /Users/divyansh/Library/Caches/deno/npm/registry.npmjs.org/@parcel/watcher-darwin-arm64/2.4.1/watcher.node
    at Object.Module._extensions..node (node:module:704:20)
    at Module.load (node:module:597:32)
    at Function.Module._load (node:module:484:12)
    at Module.require (node:module:609:19)
    at require (node:module:715:16)
    at Object.<anonymous> (file:///Users/divyansh/Library/Caches/deno/npm/registry.npmjs.org/@parcel/watcher/2.4.1/index.js:15:13)
    at Object.<anonymous> (file:///Users/divyansh/Library/Caches/deno/npm/registry.npmjs.org/@parcel/watcher/2.4.1/index.js:43:4)
    at Module._compile (node:module:659:34)
    at Object.Module._extensions..js (node:module:673:10)
    at Module.load (node:module:597:32)

@devsnek
Copy link
Member

devsnek commented Jun 10, 2024

This should be fixed in #24101, let us know if you run into more problems.

@devsnek devsnek closed this as completed Jun 10, 2024
@brc-dd
Copy link

brc-dd commented Jun 10, 2024

@devsnek I just tested with https://dl.deno.land/canary/e3b2ee183bc7497ec0432bc764678f5eda6495a7/deno-aarch64-apple-darwin.zip and @parcel/watcher is still failing (see my comment above for MRE). The error message is similar:

Watcher File change detected! Restarting!
error: Uncaught (in promise) TypeError: Unable to find register Node-API module at /Users/divyansh/Library/Caches/deno/npm/registry.npmjs.org/@parcel/watcher-darwin-arm64/2.4.1/watcher.node
    at Object.Module._extensions..node (node:module:776:20)
    at Module.load (node:module:654:32)
    at Function.Module._load (node:module:522:12)
    at Module.require (node:module:673:19)
    at require (node:module:787:16)
    at Object.<anonymous> (file:///Users/divyansh/Library/Caches/deno/npm/registry.npmjs.org/@parcel/watcher/2.4.1/index.js:15:13)
    at Object.<anonymous> (file:///Users/divyansh/Library/Caches/deno/npm/registry.npmjs.org/@parcel/watcher/2.4.1/index.js:43:4)
    at Module._compile (node:module:729:34)
    at Object.Module._extensions..js (node:module:743:10)
    at Module.load (node:module:654:32)

Should I create a separate issue?

@devsnek
Copy link
Member

devsnek commented Jun 10, 2024

Oops sorry, this got wrapped up into other sharp issues i was closing 😄 Have not verified this on macos yet.

@devsnek devsnek reopened this Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node compat node native extension related to the node-api (.node)
Projects
None yet
Development

No branches or pull requests

6 participants