Closed Jancat closed 6 years ago
Please provide more info =\ How you install it, how you use it.
yarn add sha.js
import shajs from 'shajs'
shajs('sha256').update('42').digest('hex')
Than it throws the error:
Unable to resolve module buffer
from ./node-modules/safe-buff/index.js
: Module does not exist in the module map
There's two problems at play here:
buffer
, when it should.It's listed in devDependencies
instead, which is incorrect.
I think it's an attempt to make this project Node compatible, because Node comes with a built-in 'buffer'. However, seems as this project is specifically designed to target browsers that doesn't seem to make a heap of sense.
Given we're specifically targeting browsers there's actually no reason to use safe-buffer
at all, just go ahead and use buffer
directly.
I'm assuming you're using Rollup here. rollup-plugin-node-resolve has some really weird default behaviour when targeting a browser.
In the case of a browser there's no such thing as built-ins, the setting should really be false
if you're targeting a browser. You need to update your rollup.config.js
to look like:
import nodeResolve from 'rollup-plugin-node-resolve';
/* ... */
export default {
/* ... */
plugins: [
nodeOptions({
/* ... */
preferBuiltins: false
}),
/* ... */
],
/* ... */
}
For some reason this project doesn't have a runtime dependency on buffer, when it should.
@Benjamin-Dobell the project depends on safe-buffer
, how buffer
is resolved in that package... is potentially frustrating, but, it was better than trying to resolve that issue everywhere else.
@Jancat maybe open the issue there?
@dcousens Is this package meant to run inside Node?
Because if not, I'd suggest replacing the safe-buffer
dependency with a direct dependency on buffer
. safe-buffer
is just an abstraction that allows a project to be compatible with both Node and browser; if this project isn't targeting Node then the abstraction is not necessary.
@Benjamin-Dobell it doesn't not target Node? Whether it should, is probably up for discussion, but the same question exists for all of the implementations in https://github.com/crypto-browserify .
In the past, several were targeting Node to support newer APIs in older versions, but, that may not be the case now...
Fair enough 👍
@Benjamin-Dobell up to you if you want to chase that rabbit
@dcousens I'd suggest replacing the
safe-buffer
dependency with a direct dependency onbuffer
.
Bump, a dependency issue still occurs (e.g. in latest Nuxt 3 that uses Vite instead of Webpack). There is an open PR since 2021 at https://github.com/feross/safe-buffer/pull/33...
safe-buffer
package issue?My node is
v9.2.1