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

'variable data is undeclared' when attempting to use Google Closure Compiler #516

Closed
ashpr opened this issue Jun 14, 2018 · 8 comments
Closed
Labels
enhancement New feature or improved functionality.

Comments

@ashpr
Copy link

ashpr commented Jun 14, 2018

So I'm trying to build a project of ours using ably and compress it via google closure compiler.

It throws the following error:

stdin:136807: ERROR - variable data is undeclared
if (typeof(data) == 'string')

I found it's this line here..

if (typeof(data) == 'string')

I think 'data' is meant to be 'this.data'.. if this could be changed that would be terrific.

@funkyboy
Copy link
Contributor

Thanks @ashpr for reporting this.
We also are using the closure compiler to build our minified version

Just curious, which version are you using? Here's ours: https://github.com/ably/ably-js/blob/master/package.json#L26

@funkyboy funkyboy added the enhancement New feature or improved functionality. label Jun 14, 2018
@ashpr
Copy link
Author

ashpr commented Jun 14, 2018

Here's the version I'm using bundled with the closure plugin for Webpack
https://github.com/roman01la/webpack-closure-compiler/blob/master/package.json#L27

So I'm two released versions ahead.

I did find this in the patch notes for v20180319

Stricter "strictMissingProperty" checks.

See here: https://github.com/google/closure-compiler/wiki/Releases

I suspect that might have something to do with it.

Thanks for acknowledging this @funkyboy !

@funkyboy
Copy link
Contributor

@ashpr I just tried with your version and it still works. It's not related to the version number but to the compilation_level.

We are using SIMPLE_OPTIMIZATIONS and I am guessing you are using ADVANCED_OPTIMIZATIONS. Correct?

@SimonWoolf
Copy link
Member

@funkyboy this is a bit of a moot point, the line ashpr pointed out is clearly wrong and needs to be fixed regardless

@funkyboy
Copy link
Contributor

@SimonWoolf sure. The reason I am asking is that I don't get only that error when I take up a notch the optimization level.

>>
>> browser/static/ably.js:5023: ERROR - variable data is undeclared
>>                      if (typeof(data) == 'string')
>>                                 ^^^^
>>
>> browser/static/ably.js:8464: ERROR - variable Buffer is undeclared
>>              toBase64 = function(str) { return (new Buffer(str, 'ascii')).toString('base64'); };
>>                                                     ^^^^^^
>>
>> browser/static/ably.js:11503: ERROR - variable exports is undeclared
>> if (typeof exports === "object" && exports) {
>>            ^^^^^^^
>>
>> browser/static/ably.js:11515: ERROR - variable define is undeclared
>> if (typeof define === "function" && define.amd) {
>>            ^^^^^^
>>
>> 4 error(s), 10 warning(s)
>> FAILED to run command for target: ably.js
Warning: Task "closureCompiler:ably.js" failed. Use --force to continue.

Aborted due to warnings.
ably-js>

@ashpr
Copy link
Author

ashpr commented Jun 17, 2018

@funkyboy You are correct. I only get that error in advanced builds.

Nothing else comes up I'm afraid. I have an extern for the exports variable but nothing for the define and Buffer variables so i'm not sure why they are not being flagged.

The GCC NPM repo does come pre-loaded with nodejs externs that may be automatically injected but I can't find any kind of logging to confirm.

@funkyboy
Copy link
Contributor

@ashpr Good. This change has been merged and will be included in the next release.

@ashpr
Copy link
Author

ashpr commented Jun 18, 2018

Thank you @funkyboy . Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improved functionality.
Development

No branches or pull requests

3 participants