Bitcoinjs-lib: Failed to minify the code from this file: ./node_modules/bitcoinjs-lib/src/script.js:57

Created on 2 Aug 2018  路  4Comments  路  Source: bitcoinjs/bitcoinjs-lib

I believe this is more related to an issue with create-react-app. Still, I wanted to file this issue incase the team has a solution that doesn't involve moving the bitcoinsjs-lib library outside of node_modules. Any suggestions would be appreciated! Sorry in advance if this isn't your domain or if there's a simple solution I'm missing. The bug: attempting "npm run build" results in the following error:

screen shot 2018-08-02 at 5 17 50 pm

Here is the npm log:

`

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/9.10.0_1/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 info lifecycle [email protected]~build: [email protected]
7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/harrysolovay/Desktop/making-a-template/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
9 verbose lifecycle [email protected]~build: CWD: /Users/harrysolovay/Desktop/making-a-template
10 silly lifecycle [email protected]~build: Args: [ '-c', 'react-app-rewired build' ]
11 silly lifecycle [email protected]~build: Returned: code: 1  signal: null
12 info lifecycle [email protected]~build: Failed to exec build script
13 verbose stack Error: [email protected] build: `react-app-rewired build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:304:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:961:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
14 verbose pkgid [email protected]
15 verbose cwd /Users/harrysolovay/Desktop/making-a-template
16 verbose Darwin 17.6.0
17 verbose argv "/usr/local/Cellar/node/9.10.0_1/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v10.6.0
19 verbose npm  v6.1.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] build: `react-app-rewired build`
22 error Exit status 1
23 error Failed at the [email protected] build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

`

Thank you so much for taking a look at this! Please let me know if you have any questions. And feel free to close the issue immediately if this is the wrong forum for this specific situation 馃憤

how to / question / docs

Most helpful comment

Yea for sure:

Here's the relevant section of my webpack.config.prod.js before & after:

before:

{
  test: /\.(js|jsx|mjs)$/,
  include: [
    paths.appSrc,
  ],
  loader: require.resolve('babel-loader'),
  options: {
    babelrc: true,
    compact: true,
  },
},

after:

{
  test: /\.(js|jsx|mjs)$/,
  include: [
    paths.appSrc,
    ...[
      'bitcoinjs-lib',
      'tiny-secp256k1/ecurve',
      'base64url/dist/base64url',
      'base64url/dist/pad-string',
      'bip32',
    ].map(moduleName => `${ paths.appNodeModules }/${ moduleName }`)
  ],
  loader: require.resolve('babel-loader'),
  options: {
    babelrc: true,
    compact: true,
  },
},

All 4 comments

The solution was to configure babel-loader to include modules that the console said weren't possible to minify (bitcoinjs-lib being one of them). Would be awesome if you could find a way for bitcoinjs-lib to be consumed in the CRA build process without the need for that additional configuration. Hopefully this is helpful (and not simply me complaining haha) 馃

Kind regards,

Harry

@harrysolovay can you share how you did this specifically?
Thanks

Yea for sure:

Here's the relevant section of my webpack.config.prod.js before & after:

before:

{
  test: /\.(js|jsx|mjs)$/,
  include: [
    paths.appSrc,
  ],
  loader: require.resolve('babel-loader'),
  options: {
    babelrc: true,
    compact: true,
  },
},

after:

{
  test: /\.(js|jsx|mjs)$/,
  include: [
    paths.appSrc,
    ...[
      'bitcoinjs-lib',
      'tiny-secp256k1/ecurve',
      'base64url/dist/base64url',
      'base64url/dist/pad-string',
      'bip32',
    ].map(moduleName => `${ paths.appNodeModules }/${ moduleName }`)
  ],
  loader: require.resolve('babel-loader'),
  options: {
    babelrc: true,
    compact: true,
  },
},
Was this page helpful?
0 / 5 - 0 ratings

Related issues

dakk picture dakk  路  3Comments

coingeek picture coingeek  路  4Comments

Beardcoding picture Beardcoding  路  3Comments

Mr-Mondragon picture Mr-Mondragon  路  3Comments

namnv04 picture namnv04  路  3Comments