-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Description
I'm trying to build this module with webpack in js-ipfs/examples/browser-webpack and the Buffer detection doesn't work:
ERROR in ../../node_modules/cborg/esm/lib/byte-utils.js 1:32-39
Module not found: Error: Can't resolve 'process/browser' in '/Users/alex/Documents/Workspaces/ipfs/js-ipfs/node_modules/cborg/esm/lib'
Did you mean 'browser.js'?
BREAKING CHANGE: The request 'process/browser' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
@ ../../node_modules/cborg/esm/lib/encode.js 9:0-40 192:13-18
@ ../../node_modules/cborg/esm/cborg.js 1:0-41 7:0-12:2
@ ../../packages/ipfs-core/src/components/pin/pin-manager.js
@ ../../packages/ipfs-core/src/components/index.js 93:20-48
@ ../../packages/ipfs-core/src/index.js 27:4-27
@ ../../packages/ipfs/src/index.js 12:35-55
@ ./src/components/app.js 11:11-26
@ ./src/components/index.js 7:10-26
It's good to use buffer because Buffer.allocUnsafe(size)
is significantly faster than new Uint8Array(size)
, but it's bad to use node globals.
Solutions:
- Use the process module:
import process from 'process'
export const useBuffer = !process.browser && global.Buffer && typeof global.Buffer.isBuffer === 'function';
- Use the buffer module:
import { Buffer } from 'buffer'
export const useBuffer = true;
// replace global.Buffer with Buffer
Metadata
Metadata
Assignees
Labels
No labels