calvinmetcalf / crypto-pouch

plugin for encrypted pouchdb/couchdb databases
MIT License
243 stars 43 forks source link

enhancement: support usage without chacha #43

Closed arolson101 closed 3 years ago

arolson101 commented 8 years ago

I'm using crypto-pouch through webpack in an electron app. Because chacha has a native binding, webpack can't properly package it up because of the dll. Also, using native bindings in electron typically is painful because you have to recompile it targeting a different version/configuration of node.

A simple remedy would be to use the browser version of chacha but since I don't have any backwards compatibility needs I'd like to just use crypto-pouch with just the node crypto bits.

This can be accomplished by having a separate entry point- require('crypto-pouch/gcm') or something. (I hesitate to say 'crypto-pouch/browser' because that could imply using chacha/browser.) This entry point would not have any references to chacha; if you tried to use any of the chacha stuff it would have to throw an exception.

calvinmetcalf commented 8 years ago

this should work fine if the native bindings fail to compile, they are listed as an optional dependency and we fall back to a pure js version if that is the case

arolson101 commented 8 years ago

They don't fail to compile, and webpack also doesn't fail. It's once electron tries to load, it expects to find the dll but it's not in the bundle.

calvinmetcalf commented 8 years ago

the loading of the native module is inside of a try catch, it should work fine even if it fails (there is also no dll involved that I am aware of) so I'm somewhat confused but what you are saying, can you post a screen shot or stack trace?

On Sun, Dec 4, 2016 at 12:32 PM arolson101 notifications@github.com wrote:

They don't fail to compile, and webpack also doesn't fail. It's once electron tries to load, it expects to find the dll but it's not in the bundle.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/calvinmetcalf/crypto-pouch/issues/43#issuecomment-264717685, or mute the thread https://github.com/notifications/unsubscribe-auth/ABE4n21p5BgvoXL22lzazCKTLAvYRWG7ks5rEvkigaJpZM4LDV-C .

arolson101 commented 8 years ago

this is from webpack

WARNING in ../~/bindings/package.json
Module parse failed: C:\p\node_modules\bindings\package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:9)
    at Parser.pp$4.raise (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15)
    at Parser.pp.unexpected (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10)
    at Parser.pp.semicolon (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:581:61)
    at Parser.pp$1.parseExpressionStatement (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:966:10)
    at Parser.pp$1.parseStatement (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:730:24)
    at Parser.pp$1.parseBlock (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:981:25)
    at Parser.pp$1.parseStatement (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:709:33)
    at Parser.pp$1.parseTopLevel (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:638:25)
    at Parser.parse (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:516:17)
    at Object.parse (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:3098:39)
    at Parser.parse (C:\p\node_modules\webpack\lib\Parser.js:902:15)
    at DependenciesBlock.<anonymous> (C:\p\node_modules\webpack\lib\NormalModule.js:104:16)
    at DependenciesBlock.onModuleBuild (C:\p\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:310:10)
    at nextLoader (C:\p\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:275:25)
    at C:\p\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:259:5
    at Storage.provide (C:\p\node_modules\webpack\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:52:20)
    at CachedInputFileSystem.readFile (C:\p\node_modules\webpack\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:140:24)
    at DependenciesBlock.onLoadPitchDone (C:\p\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:255:7)
    at DependenciesBlock.loadPitch (C:\p\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:182:27)
    at DependenciesBlock.doBuild (C:\p\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:241:4)
    at DependenciesBlock.build (C:\p\node_modules\webpack\lib\NormalModule.js:84:14)
    at Compilation.buildModule (C:\p\node_modules\webpack\lib\Compilation.js:126:9)
    at C:\p\node_modules\webpack\lib\Compilation.js:309:10
    at C:\p\node_modules\webpack\lib\NormalModuleFactory.js:58:13
    at NormalModuleFactory.applyPluginsAsyncWaterfall (C:\p\node_modules\webpack\node_modules\tapable\lib\Tapable.js:75:69)
    at onDoneResolving (C:\p\node_modules\webpack\lib\NormalModuleFactory.js:38:11)
    at onDoneResolving (C:\p\node_modules\webpack\lib\NormalModuleFactory.js:121:6)
    at C:\p\node_modules\webpack\lib\NormalModuleFactory.js:116:7
    at C:\p\node_modules\webpack\node_modules\async\lib\async.js:726:13
    at C:\p\node_modules\webpack\node_modules\async\lib\async.js:52:16
 @ ../~/bindings ^\.\/.*$

WARNING in ../~/bindings/README.md
Module parse failed: C:\p\node_modules\bindings\README.md Unexpected token (2:3)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:3)
    at Parser.pp$4.raise (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15)
    at Parser.pp.unexpected (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10)
    at Parser.pp$3.parseExprAtom (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:1822:12)
    at Parser.pp$3.parseExprSubscripts (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:1715:21)
    at Parser.pp$3.parseMaybeUnary (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:1692:19)
    at Parser.pp$3.parseExprOp (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:1656:43)
    at Parser.pp$3.parseExprOp (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:1658:21)
    at Parser.pp$3.parseExprOps (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:1639:17)
    at Parser.pp$3.parseMaybeConditional (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:1620:21)
    at Parser.pp$3.parseMaybeAssign (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:1597:21)
    at Parser.pp$3.parseExpression (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:1573:21)
    at Parser.pp$1.parseStatement (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:727:47)
    at Parser.pp$1.parseTopLevel (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:638:25)
    at Parser.parse (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:516:17)
    at Object.parse (C:\p\node_modules\webpack\node_modules\acorn\dist\acorn.js:3098:39)
    at Parser.parse (C:\p\node_modules\webpack\lib\Parser.js:902:15)
    at DependenciesBlock.<anonymous> (C:\p\node_modules\webpack\lib\NormalModule.js:104:16)
    at DependenciesBlock.onModuleBuild (C:\p\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:310:10)
    at nextLoader (C:\p\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:275:25)
    at C:\p\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:259:5
    at Storage.finished (C:\p\node_modules\webpack\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:38:16)
    at C:\p\node_modules\webpack\node_modules\enhanced-resolve\node_modules\graceful-fs\graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3)
 @ ../~/bindings ^\.\/.*$
Child extract-text-webpack-plugin:
        + 8 hidden modules
Child extract-text-webpack-plugin:
        + 62 hidden modules
calvinmetcalf commented 8 years ago

if you put chacha-native as an external dependency that should do the trick,

arolson101 commented 7 years ago

That did fix the error, though it would still be nice to reduce unneeded dependencies in the bundle

calvinmetcalf commented 7 years ago

You could probably exclude chacha instead of chacha-native and assuming you did have any old documents that would likely work fine

arolson101 commented 7 years ago

If I set chacha as external I get:

external "chacha":1
Uncaught ReferenceError: chacha is not defined
garbados commented 3 years ago

Howdy @arolson101 ! We just published version 4.0 which no longer bundles chacha. Can you try again and let me know how it goes? I can help you debug from there.

I'm closing this issue for now since it's been about five years. I can re-open it at your request :)