s0l0ist / node-seal

Homomorphic Encryption for TypeScript or JavaScript - Microsoft SEAL
https://s0l0ist.github.io/node-seal/
MIT License
191 stars 24 forks source link

Cannot import from Javascript(browser) #130

Closed san1ker closed 2 years ago

san1ker commented 2 years ago

Describe the bug Cannot import node-seal from browser (not node-js)

To Reproduce Trying import node-seal from browser, my Javascript can not import node-seal.

(Based on Full example so other lines are same. And works perfectly in Node.js)

main.html ....<script type="module" src="/main.js" ></script>....

main.js (async () => { import SEAL from 'node-seal'; ......

And I got an error like: Uncaught SyntaxError: Unexpected identifier (at main.js:12:12)

So I tried other methods to import node-seal but could not solve it.

tried: const SEAL = require('node-seal'); error: Uncaught (in promise) ReferenceError: require is not defined

tried: import SEAL from 'node-seal/throws_wasm_web_umd' error: Failed to resolve module specifier "node-seal/throws_wasm_web_umd". Relative references must start with either "/", "./", or "../".

tried: import {SEAL} from './node_modules/node-seal/throws_wasm_node_umd.js' error: The requested module './node_modules/node-seal/throws_wasm_node_umd.js' does not provide an export named 'SEAL' (at main.js:1:9)

Is there something I missed??

thanks.

Environment

s0l0ist commented 2 years ago

The package assumes you're using CommonJS or ES modules.

If you want to have a direct import in HTML, run npm install to get the package installed in the root of your project. Then, create index.html with the following contents:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <script src="./node_modules/node-seal/throws_wasm_web_umd.js"></script>
  </head>
  <body>
    You're debugging the WASM target
  </body>
</html>
san1ker commented 2 years ago

There is example under dev/**.html I got it Thanks:)