Search code examples
angularfirebaseionic2angularfire2rollupjs

Firebase ionic2-rc0 and rollup - “rollup: Use of `eval` is strongly discouraged”


I've updated my ionic app from beta 11 to rc0. So it means I've switched from angular2 rc4 to angular2 stable, from typescript 1.8 to 2 and using the rollupjs module bundler.

I have configured AngularFire2 according to this blog post: Getting Started with Ionic 2 RC0, Firebase 3 + AngularFire 2

I'm not able to compile and getting this error:

rollup: Use ofeval(in c:\XXX\node_modules\angularfire2\node_modules\firebase\firebase.js) is strongly discouraged, as it poses security risks and may cause issues with minification. See https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval for more details

Anyone knows what's going on and how to tackle this?


Solution

  • Long-term, the solution is for Firebase to remove direct eval from their code, as it's not actually necessary here (it's just being used to parse JSON. JSON.parse is much faster, and support is basically a non-issue these days).

    In the meantime, a possible (albeit hacky) workaround might be to convert that eval into an indirect eval (see the troubleshooting note to understand the difference), using rollup-plugin-replace:

    // rollup.config.js
    import nodeResolve from 'rollup-plugin-node-resolve';
    import commonjs from 'rollup-plugin-commonjs';
    import replace from 'rollup-plugin-replace';
    // ...etc
    
    export default {
      // ...other config...
      plugins: [
        nodeResolve({...}),
        commonjs({...}),
        replace({
          include: 'node_modules/firebase/firebase.js',
          values: {
            'eval(' : '[eval][0]('
          }
        })
      ]
    };