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

Experimental npm support did not resolve the node dependencies (sharp, util) #16277

Open
nestarz opened this issue Oct 14, 2022 · 3 comments
Open

Comments

@nestarz
Copy link

nestarz commented Oct 14, 2022

Env

Deno version:
deno 1.26.1

Run the code:

import sharp from 'npm:sharp';

And throw exception:

error: Uncaught (in promise) Error: Cannot find module 'util'
Require stack:
- /Users/dd/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.31.1/lib/constructor.js
- /Users/dd/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.31.1/lib/index.js
- /Users/dd/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.31.1/lib/index.js
    at Function.Module._resolveFilename (deno:ext/node/02_require.js:615:17)
    at Function.Module._load (deno:ext/node/02_require.js:447:29)
    at Module.require (deno:ext/node/02_require.js:658:21)
    at require (deno:ext/node/02_require.js:789:18)
    at Object.<anonymous> (file:///Users/dd/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.31.1/lib/constructor.js:3:14)
    at Object.<anonymous> (file:///Users/dd/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.31.1/lib/constructor.js:425:4)
    at Module._compile (deno:ext/node/02_require.js:719:36)
    at Object.Module._extensions..js (deno:ext/node/02_require.js:752:12)
    at Module.load (deno:ext/node/02_require.js:636:34)
    at Function.Module._load (deno:ext/node/02_require.js:493:14)
Watcher Process finished. Restarting on file change...

Then find the keyword in the sharp package:

$ grep -r 'util' ~/Library/Cache/deno/npm/registry.npmjs.org/sharp/0.31.1
/Users/dd/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.31.1/lib/constructor.js:const util = require('util');
/Users/dd/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.31.1/lib/constructor.js:const debuglog = util.debuglog('sharp');


Expected

Resolve the node dependencies.

Additional Info

If I remove the util line, there is the same error with the stream package:

error: Uncaught (in promise) Error: Cannot find module 'stream'

Also, the following alternative is not working:
import sharp from "https://esm.sh/[email protected]";
with error:

Something went wrong installing the "sharp" module

Dynamic require of "../build/Release/sharp-darwin-arm64v8.node" is not supported
@janosh
Copy link

janosh commented Mar 8, 2023

Related issue lovell/sharp#2583

@birkskyum
Copy link
Contributor

@birkskyum
Copy link
Contributor

I'm still fighting Sharp installation as well.

➜ deno task dev               
Task dev deno run ./src/app.ts
✅ Granted all read access.
✅ Granted all env access.
error: Uncaught (in promise) Error: 
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp-darwin-arm64v8.node'
Require stack:
- /Users/admin/repos/node_modules/.deno/[email protected]/node_modules/sharp/lib/sharp.js
- /Users/admin/repos/node_modules/.deno/[email protected]/node_modules/sharp/lib/constructor.js
- /Users/admin/repos/node_modules/.deno/[email protected]/node_modules/sharp/lib/index.js
- /Users/admin/repos/node_modules/.deno/[email protected]/node_modules/join-images/lib/main.js
- /Users/admin/repos/node_modules/.deno/[email protected]/node_modules/join-images/lib/main.js

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/admin/repos/node_modules/.deno/[email protected]/node_modules/sharp/lib/sharp.js:37:9)
    at Object.<anonymous> (file:///Users/admin/repos/node_modules/.deno/[email protected]/node_modules/sharp/lib/sharp.js:40:4)
    at Module._compile (node:module:745:34)
    at loadMaybeCjs (node:module:770:10)
    at Object.Module._extensions..js (node:module:755:12)
    at Module.load (node:module:662:32)
    at Function.Module._load (node:module:534:12)
    at Module.require (node:module:681:19)
    at require (node:module:812:16)
    at Object.<anonymous> (file:///Users/admin/repos/node_modules/.deno/[email protected]/node_modules/sharp/lib/constructor.js:11:1)

    info: Trying to execute an npm package using Node-API addons,
          these packages require local `node_modules` directory to be present.
    hint: Add `"nodeModulesDir": "auto" option to `deno.json`, and then run
          `deno install --allow-scripts=npm:<package> --entrypoint <script>` to setup `node_modules` directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants