denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.04k stars 5.23k forks source link

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

Open nestarz opened 1 year ago

nestarz commented 1 year ago

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/sharp@0.31.1"; with error:

Something went wrong installing the "sharp" module

Dynamic require of "../build/Release/sharp-darwin-arm64v8.node" is not supported
janosh commented 1 year ago

Related issue https://github.com/lovell/sharp/issues/2583

birkskyum commented 1 year ago

Related to: