New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@0x/subproviders Doesn't Work With Angular 6 When Doing Production Builds For Client or Server #1195

Open
pointtoken opened this Issue Oct 29, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@pointtoken

pointtoken commented Oct 29, 2018

Here is a simple repo, taken from the Angular Universal Starter: https://github.com/pointtoken/universal-starter/tree/0x

You'll see I added the 0x SubProviders library and try to instantiate it. I also had to deal with Angular not liking crypto with this hack

https://gist.github.com/niespodd/1fa82da6f8c901d1c33d2fcbb762947d

Which I learned about from here:

ethereum/web3.js#1555

If I create a production build and just try to serve the browser files, it fails at runtime.

If I try to create a build that runs on the server (which runs a different webpack that targets node), it won't even build:

ERROR in ./node_modules/scrypt/index.js
Module not found: Error: Can't resolve './build/Release/scrypt' in '/Users/admin/repos/temp/universal-starter/node_modules/scrypt'
 @ ./node_modules/scrypt/index.js 3:19-52
 @ ./node_modules/scrypt.js/node.js
 @ ./node_modules/ethereumjs-wallet/index.js
 @ ./node_modules/ganache-core/lib/statemanager.js
 @ ./node_modules/ganache-core/lib/subproviders/geth_api_double.js
 @ ./node_modules/ganache-core/lib/provider.js
 @ ./node_modules/ganache-core/index.js
 @ ./node_modules/@0x/subproviders/lib/src/subproviders/ganache.js
 @ ./node_modules/@0x/subproviders/lib/src/index.js
 @ ./dist/server/main.js
 @ ./server.ts

ERROR in ./node_modules/got/index.js
Module not found: Error: Can't resolve './package' in '/Users/admin/repos/temp/universal-starter/node_modules/got'
 @ ./node_modules/got/index.js 22:12-32
 @ ./node_modules/swarm-js/lib/files.js
 @ ./node_modules/swarm-js/lib/api-node.js
 @ ./node_modules/web3-bzz/src/index.js
 @ ./node_modules/ganache-core/node_modules/web3/src/index.js
 @ ./node_modules/ganache-core/lib/statemanager.js
 @ ./node_modules/ganache-core/lib/subproviders/geth_api_double.js
 @ ./node_modules/ganache-core/lib/provider.js
 @ ./node_modules/ganache-core/index.js
 @ ./node_modules/@0x/subproviders/lib/src/subproviders/ganache.js
 @ ./node_modules/@0x/subproviders/lib/src/index.js
 @ ./dist/server/main.js
 @ ./server.ts

ERROR in ./node_modules/got/index.js
Module not found: Error: Can't resolve 'electron' in '/Users/admin/repos/temp/universal-starter/node_modules/got'
 @ ./node_modules/got/index.js 45:20-39
 @ ./node_modules/swarm-js/lib/files.js
 @ ./node_modules/swarm-js/lib/api-node.js
 @ ./node_modules/web3-bzz/src/index.js
 @ ./node_modules/ganache-core/node_modules/web3/src/index.js
 @ ./node_modules/ganache-core/lib/statemanager.js
 @ ./node_modules/ganache-core/lib/subproviders/geth_api_double.js
 @ ./node_modules/ganache-core/lib/provider.js
 @ ./node_modules/ganache-core/index.js
 @ ./node_modules/@0x/subproviders/lib/src/subproviders/ganache.js
 @ ./node_modules/@0x/subproviders/lib/src/index.js
 @ ./dist/server/main.js
 @ ./server.ts 

It seems like there is a lot of code in the subprovider library that isn't being shaken out -- could this library be made more modular? Or are there webpack tricks/hacks that need to be in place?

@stale

This comment has been minimized.

stale bot commented Dec 12, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 12, 2018

@dekz

This comment has been minimized.

Member

dekz commented Dec 13, 2018

We're going to look into tree shaking better for the subproviders package. At the very least we should split out ganache-core (used in testing) from the rest of the subproviders.

#1400

Also had a bit of luck following this comment here, trufflesuite/ganache-cli#204 (comment).

var scryptNative = require("scrypt")
  , Crypto = require("crypto")
  , Os = `require("os")

// Replacing "./build/Release/scrypt" with "scrypt" or "./build/Release/scrypt.node"

in node_modules/scrypt/index.js.

universal-starter λ yarn build:ssr && yarn serve:ssr                                                                                                                                            0x*
yarn run v1.6.0
(node:53170) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
$ npm run build:client-and-server-bundles && npm run webpack:server

> ng-universal-demo@0.0.0 build:client-and-server-bundles /Users/jacob/tmp/zz/universal-starter
> ng build --prod && ng run ng-universal-demo:server:production


Date: 2018-12-13T06:28:47.555Z
Hash: 1f2a73c09ad915f10789
Time: 19955ms
chunk {0} 0.5ec9c28020fef7750e9a.js () 1.04 kB  [rendered]
chunk {1} runtime.e8e93db712066d1877cd.js (runtime) 1.84 kB [entry] [rendered]
chunk {2} styles.34c57ab7888ec1573f9c.css (styles) 0 bytes [initial] [rendered]
chunk {3} polyfills.3c5058f2e65cfe264ee1.js (polyfills) 64.5 kB [initial] [rendered]
chunk {4} main.3e2c9967167f0e9a4d8e.js (main) 258 kB [initial] [rendered]

Date: 2018-12-13T06:28:53.988Z
Hash: 8d1d263f64894cac1925
Time: 4079ms
chunk {main} main.js (main) 37.1 kB [entry] [rendered]

> ng-universal-demo@0.0.0 webpack:server /Users/jacob/tmp/zz/universal-starter
> webpack --config webpack.server.config.js --progress --colors

Hash: edc9ac9d94a8a7e43b3d
Version: webpack 4.6.0
Time: 2446ms
Built at: 12/13/2018 5:28:57 PM
       Asset      Size  Chunks             Chunk Names
   server.js  4.98 MiB       0  [emitted]  server
prerender.js  4.29 MiB       1  [emitted]  prerender
Entrypoint server = server.js
Entrypoint prerender = prerender.js
  [0] ./server.ts 1.49 KiB {0} [built]
  [2] external "events" 42 bytes {0} {1} [built]
  [3] external "fs" 42 bytes {0} {1} [built]
  [4] external "timers" 42 bytes {0} {1} [optional] [built]
  [5] external "crypto" 42 bytes {0} {1} [built]
[207] ./src lazy namespace object 160 bytes {0} {1} [built]
[215] external "url" 42 bytes {0} {1} [built]
[271] external "http" 42 bytes {0} {1} [built]
[272] external "https" 42 bytes {0} {1} [built]
[273] external "os" 42 bytes {0} {1} [built]
[283] external "path" 42 bytes {0} {1} [built]
[300] external "net" 42 bytes {0} [built]
[398] ./dist/server/main.js 36.3 KiB {0} {1} [built]
[401] ./prerender.ts 1.48 KiB {1} [built]
[402] ./static.paths.ts 62 bytes {1} [built]
    + 388 hidden modules
✨  Done in 32.20s.
yarn run v1.6.0
(node:53192) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
$ node dist/server
(node:53200) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Node Express server listening on http://localhost:4000

@stale stale bot removed the stale label Dec 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment