scatter-js
scatter-js copied to clipboard
Scatter fails at compile time in Angular project
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",
Looks like somehow node.js code is picked up instead of browser code when angular is compiling
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
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.
Also, can you test without the lynx plugin? Perhaps there's something in there which isn't transpiling properly.
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>
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",