jedisct1 / libsodium.js

libsodium compiled to Webassembly and pure JavaScript, with convenient wrappers.
Other
968 stars 138 forks source link

Add `"path": false` to package.json's browser section. #309

Closed NfNitLoop closed 1 year ago

NfNitLoop commented 1 year ago

It looks like the package.json already has a "fs": false. I think path needs to be added there too.

Without it, bundlers may try to make it available in the browser, or give an error. Here's the error I get from esbuild:

> node esbuilder.mjs

✘ [ERROR] Could not resolve "path"

    node_modules/libsodium/dist/modules/libsodium.js:1:966:
      1 │ ... process.versions&&"string"==typeof process.versions.node,c="";f?(c=e?require("path").dirname(c)+"/":__dirname+"/",n=()=>{i||(E=require("fs"),i=require("path"))}...
        ╵                                                                                  ~~~~~~

  The package "path" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

It appears I'm not the first person to run into this: https://github.com/evanw/esbuild/issues/1786

sineemore commented 1 year ago

While waiting for the code to land in the registry it is possible to fix esbuild error with esbuild-plugin-ignore or with esbuild alias option: {"path": "./src/dummy.js"} where dummy.js is an empty file. Both seem to work fine.