Skip to content
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

compilation errors caused by rollup deleting minimized firebase semicolon #1275

Closed
MichaelRando opened this issue Jan 19, 2017 · 24 comments
Closed

Comments

@MichaelRando
Copy link

MichaelRando commented Jan 19, 2017

I have a firebase project that rollup is failing to build. I determined that rollup was corrupting the auth.js file out of firebase by removing meaningful semicolon. Rolling back rollupjs to version 0.36.1 "fixed" me. You probably want to look at this. g+oe|0a.h[0] is the broken substr.
Minimized rollup.config.js follows:

import replace from 'rollup-plugin-replace'
export default {
    entry:  'node_modules/firebase/auth.js',
    dest:   './dist/auth.js',
    format: 'iife',
plugins:
   [
      replace({
         'process.env.NODE_ENV': JSON.stringify( 'production' )
      })
   ]
}
@kzc
Copy link
Contributor

kzc commented Jan 19, 2017

Your rollup config works fine with:

There is a warning about firebase's use of eval, but it's just a warning.

@MichaelRando
Copy link
Author

Sure, it creates an output file. I would prefer it to create a valid javascript file, instead. For example:
instead of string: 'g+oe|0a.h[0]', I like the original file's: 'g+oe|0;a.h[0]'

@kzc
Copy link
Contributor

kzc commented Jan 19, 2017

I ran the generated rollup output file through [email protected] as well as [email protected] and confirmed it is valid javascript file.

I did not see the string in question. Please verify the versions of the modules match the ones I listed above.

@kzc
Copy link
Contributor

kzc commented Jan 19, 2017

I see what you mean now. The rollup output contains:

y<<26)^(y>>>11|y<<21)^(y>>>25|y<<7))|0,g=g+(vb[b]|0)|0,g=f+(g+(c[b]|0)|0)|0,f=Wa,Wa=Eb,Eb=y,y=n+g|0,n=k,k=e,e=d,d=g+oe|0a.h[0]=a.h[0]+d|0;a.h[1]=a.h[1]+e|0;a.h[2]=a.h[2]+k|0;a.h[3]=a.h[3]+n|0;a.h[4]=a.h[4]+y|0;a.h[5]=a.h[5]+Eb|0;a.h[6]=a.h[6]+Wa|0;a.h[7]=a.h[7]+f|0;};

Must be some issue with line wrap.

@kzc
Copy link
Contributor

kzc commented Jan 19, 2017

I had run the original input through uglifyjs -b initially which had worked.

@kzc
Copy link
Contributor

kzc commented Jan 19, 2017

Repro:

rollup version 0.41.4

$ cat r.js

for(var x=1;x<2;x++)var d=x|0;console.log(d);

$ rollup r.js -f es

for(var x=1;x<2;x++)var d=x|0console.log(d);

$ rollup r.js -f es | node

[stdin]:1
for(var x=1;x<2;x++)var d=x|0console.log(d);
                             ^^^^^^^
SyntaxError: Unexpected identifier

Possible fix:

--- a/src/ast/nodes/VariableDeclaration.js
+++ b/src/ast/nodes/VariableDeclaration.js
@@ -98,7 +98,7 @@ export default class VariableDeclaration extends Node {
                        const needsSemicolon = !forStatement.test( this.parent.type );
 
                        if ( this.end > c ) {
-                               code.overwrite( c, this.end, needsSemicolon ? ';' : '' );
+                               code.overwrite( c, this.end, needsSemicolon ? ';' : '\n' );
                        } else if ( needsSemicolon  ) {
                                this.insertSemicolon( code );
                        }

Either that or unconditionally introduce curly braces around the body of loops similar to how Bublé does it.

@MichaelRando
Copy link
Author

could be a pull request?

@kzc
Copy link
Contributor

kzc commented Feb 23, 2017

Sure, go for it.

When you make a PR be sure to include the test above. See ffe6b0b for an example of a test.

@kylecordes
Copy link

I have encountered the same bug, in the same context of firebase. I'm trying to understand why this bug somehow leaves so much other code working correctly. Reading the source code (around the lines in the diff above), it sure seems like this would not be a very rare edge case.

@kylecordes
Copy link

kylecordes commented Feb 25, 2017

Sed hackery, for anyone stuck by this bug:

# Remove me when fixed: https://github.com/rollup/rollup/issues/1275
sed -i.bak "s/needsSemicolon \? ';' : ''/needsSemicolon ? \';\' : '\\\\n'/g" node_modules/rollup/dist/rollup.js

This is an ugly, ugly thing to do, but it got my build process back up and going without having to roll back to a pre-October rollup.

@kzc
Copy link
Contributor

kzc commented Feb 25, 2017

I'm trying to understand why this bug somehow leaves so much other code working correctly.

The problem manifests itself more often when the input is minified. See: #1275 (comment)

@kylecordes
Copy link

@kzc Thanks - now I get it. It is an unusual coding pattern that hits this bug. Something a minifier would write, not something a human would write. Hence Firebase - which is distributed in minified form.

kzc referenced this issue in sveltejs/svelte-hackernews Mar 3, 2017
@MichaelRando
Copy link
Author

still happens in 0.41.5. The broken auth statement is d = g + gh | 0a.h[0] = a.h[0] in auth.js of firebase 3.7.1

@kzc
Copy link
Contributor

kzc commented Mar 10, 2017

It still happens because no PR was made.

@MichaelRando
Copy link
Author

I tried to use babili minifier with sourcemaps, which requires rollup > 0.41.5. But this bug is still happening in rollup 0.41.6. I think I'll have to try the sed command.

@hugomrdias
Copy link

this shouldnt be ignored ! firebase is unusable with rollup
should we go we this fix ? #1275 (comment)

@olsonpm
Copy link
Contributor

olsonpm commented May 14, 2017

As kzc mentioned, feel free to create a PR with that fix

@orbitbot
Copy link

I tried the suggested change in #1275 (comment) , now the setup compiles with importing firebase, however with my current setup I get

app.js:1601 Uncaught TypeError: Cannot read property 'navigator' of undefined
    at app.js:1601
    at app.js:1868
    at app.js:1870
    at commonjsGlobal (app.js:4)
    at app.js:5

during page load no matter if the fix is applied or not. This is with rollup 0.41.6 and buble.

@olsonpm
Copy link
Contributor

olsonpm commented May 18, 2017

please create a new issue with a reproduction

@orbitbot
Copy link

After banging my head against the wall for a while I realsed that this is an issue with the way the Firebase source refers to this in firebase/database in my case, so a workaround similar to #1007 (comment) seems to have solved the issue for now.

With import replace from 'rollup-plugin-replace' in a rollup.config.js

    replace({
      include: '**/firebase/database.js',
      values: { 'aa.navigator': 'window.navigator' }
    }),

seems to do the trick. This is with rollup 0.41.6 and firebase 3.9.0 / 4.0.0. It would seem that my problems are unrelated to the original issue reported here, which for me seems to work out of the box.

@kleeb
Copy link

kleeb commented May 30, 2017

any news?

@Shyam-Chen
Copy link

Try firebase v4.1.

@kleeb
Copy link

kleeb commented Jun 20, 2017

Thanks @Shyam-Chen !
firebase 4.1.2 solved it
for Ionic / Angular users angularfire2 4.0.0-rc.1

@Rich-Harris
Copy link
Contributor

fixed in 0.46

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

No branches or pull requests

10 participants