sodium-friends / sodium-universal

Universal wrapper for sodium-javascript and sodium-native working in Node.js and the Browser
MIT License
69 stars 19 forks source link

3.0.3 not working with browserify #6

Open rhodey opened 3 years ago

rhodey commented 3 years ago

Hello, I am running into this issue while trying to bundle hypercore for a web app. I have put together a minimal example project that fails to bundle with browserify. I have been trying to fix this myself but am not well experienced with browserify. Any help would be greatly appreciated, thank you.

https://github.com/rhodey/sodium-debug

> Error: Can't walk dependency graph: Cannot find module './crypto_auth' from '/home/rhodey/dev/dsp/js/sodium-debug/node_modules/sodium-universal/index.js'
    required by /home/rhodey/dev/dsp/js/sodium-debug/node_modules/sodium-universal/index.js
        at /home/rhodey/.nvm/versions/node/v14.13.1/lib/node_modules/browserify/node_modules/resolve/lib/async.js:137:35
        at load (/home/rhodey/.nvm/versions/node/v14.13.1/lib/node_modules/browserify/node_modules/resolve/lib/async.js:156:43)
            at onex (/home/rhodey/.nvm/versions/node/v14.13.1/lib/node_modules/browserify/node_modules/resolve/lib/async.js:181:17)
            at /home/rhodey/.nvm/versions/node/v14.13.1/lib/node_modules/browserify/node_modules/resolve/lib/async.js:15:69
                at FSReqCallback.oncomplete (fs.js:181:21)
rhodey commented 3 years ago

Update: I switched my example to use v3.0.2 and the error went away, appears to be an issue introduced in 3.0.3

paul90 commented 3 years ago

A couple of days ago I had the same problem, with Cannot find module './crypto_auth'.

Looking a little deeper, and comparing the contents of the v3.0.3 package from npm, and cloning this project's repo locally. It looks very much as if the prepublish script didn't get run before the package was published. At least manually running it creates ./crypto_auth.js, and the package can be installed locally using npm i $(npm pack ../sodium-universal | tail -1) and not get that error.

RangerMauve commented 3 years ago

Also running into this.

4c656554 commented 3 years ago

Me too. I think it originates with this commit, to sodium-javascript:

https://github.com/sodium-friends/sodium-javascript/commit/656d6d251e88a6e139869f3e244c23a3ad91eeea

and this one in sodium-universal:

https://github.com/sodium-friends/sodium-universal/commit/e97357e4d280e9c04e6dc406e8c1cd38d5b8b462

4c656554 commented 3 years ago

A couple of days ago I had the same problem, with Cannot find module './crypto_auth'.

Looking a little deeper, and comparing the contents of the v3.0.3 package from npm, and cloning this project's repo locally. It looks very much as if the prepublish script didn't get run before the package was published. At least manually running it creates ./crypto_auth.js, and the package can be installed locally using npm i $(npm pack ../sodium-universal | tail -1) and not get that error.

Forgive me, where is the prepublish script, and when should it normally be run? During build?

paul90 commented 3 years ago

The prepublish script is defined in package.json.

https://github.com/sodium-friends/sodium-universal/blob/42fc47255a24107f6434271918c8b47ec243be8f/package.json#L19

It should be noted that the prepublish script was deprecated in npm@5 and running npm install in the cloned repo gives the warning:

npm WARN prepublish-on-install As of npm@5, `prepublish` scripts are deprecated.
npm WARN prepublish-on-install Use `prepare` for build steps and `prepublishOnly` for upload-only.
npm WARN prepublish-on-install See the deprecation note in `npm help scripts` for more information.

With the version of npm that comes with Node 14.15.1, npm 6.14.9, it looks as prepublish is treated as if it was prepare. But, I see some comments that indicate that this might not have been the case with some versions of npm@6

4c656554 commented 3 years ago

Thanks to @paul90, I solved it like this.

Note I am not experienced at building node projects so perhaps this will break something somewhere else. But it worked for me:

  1. cd into the yourPath/node_modules/sodium-universal/build-scripts dir
  2. run node generate.js
  3. go back to your parent module and build as normal
paul90 commented 3 years ago

The release of sodium-universal@3.0.4 should have resolved this issue.