scatter-js icon indicating copy to clipboard operation
scatter-js copied to clipboard

Scatter fails at compile time in Angular project

Open mwawrusch opened this issue 6 years ago • 6 comments

I get the following error:

ERROR in ./node_modules/cipher-base/index.js
Module not found: Error: Can't resolve 'stream' in '/Users/mwawrusch/Dev/d1/node_modules/cipher-base'
ERROR in ./node_modules/hash-base/index.js
Module not found: Error: Can't resolve 'stream' in '/Users/mwawrusch/Dev/d1/node_modules/hash-base'

my versions:

"scatterjs-core": "2.7.7",
        "scatterjs-plugin-eosjs2": "1.5.0",
        "scatterjs-plugin-lynx": "1.5.0",

mwawrusch avatar Jan 27 '19 23:01 mwawrusch

Looks like somehow node.js code is picked up instead of browser code when angular is compiling

mwawrusch avatar Jan 28 '19 01:01 mwawrusch

Some more info I found (still not working though): https://github.com/steemit/steem-js/issues/379 https://github.com/ethereum/web3.js/issues/1611

This is a proposed workaround:

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

mwawrusch avatar Jan 29 '19 19:01 mwawrusch

Hmm, have you tried adding the babel fix? npm i -D @babel/runtime It looks like perhaps it's trying to transpile it before packing it and failing to do so.

nsjames avatar Jan 30 '19 07:01 nsjames

Also, can you test without the lynx plugin? Perhaps there's something in there which isn't transpiling properly.

nsjames avatar Jan 30 '19 08:01 nsjames

edit tsconfig.json,add these line : "paths": { "hash-base": [ "./node_modules/jszip/dist/jszip.js", ], "cipher-base": [ "./node_modules/jszip/dist/jszip.js", ] }, then, add the codes in index.html: <script> var global = global || window; var Buffer = Buffer || []; var process = process || { env: { DEBUG: undefined }, version: [] }; </script>

IsQiao avatar May 13 '19 08:05 IsQiao

For angular 6+ make sure to run npm i -D @babel/runtime

Create a patch.js file with the following: const fs = require('fs'); const f = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';

fs.readFile(f, 'utf8', function (err,data) { if (err) { return console.log(err); } let result = data.replace(/node: false/g, "node: {crypto: true, stream: true, fs: 'empty', net: 'empty'}");

fs.writeFile(f, result, 'utf8', function (err) { if (err) return console.log(err); }); });

Add to your package.json "scripts": { "postinstall": "node patch.js",

shawnrmoss avatar May 27 '19 02:05 shawnrmoss