question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proxy & localStorage no longer working in v20170423

See original GitHub issue

last time I ran my project through Closure everything went fine (with version v20170218). But now today with version v20170423 it gets errors, with absolutely nothing changed in the file:

app.js:260: ERROR - variable current_player is undeclared
    current_player = +player;
    ^^^^^^^^^^^^^^

app.js:280: ERROR - variable localStorage is undeclared
    localStorage.setItem("savestate", JSON.stringify(savestate));
    ^^^^^^^^^^^^

app.js:312: ERROR - variable Proxy is undeclared
const undo_history = new Proxy(_move_history[0], {
                         ^^^^^

app.js:451: ERROR - variable right_click_tile is undeclared
    if (right_click_tile !== null)
        ^^^^^^^^^^^^^^^^

but in the web interface it does not get any error.

I run my file with those settings:

  • compilation_level ADVANCED_OPTIMIZATIONS
  • language_in ES7
  • language_out ES5_STRICT

Source: https://gitlab.com/gumiko/contagion/blob/master/app.js

My build script gets Closure from http://dl.google.com/closure-compiler/compiler-latest.zip

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
q2pcommented, Jun 27, 2020

@brad4d, the problem is that the compiler doesn’t know what a localStorage is. Right now you have to manually declare localStorage in an extern.js, which is weird, because Storage API have been supported by all major browsers for 10 years now, and is used often.

Here are the steps to reproduce:

Contents of app.js

localStorage.getItem("a")

Compiler arguments

java -jar closure-compiler-v20200614.jar --js ./app.js --js_output_file ./compiled.js --env BROWSER --warning_level VERBOSE

Output:

./app.js:1: ERROR - [JSC_UNDEFINED_VARIABLE] variable localStorage is undeclared
  1| localStorage.getItem("a")
     ^^^^^^^^^^^^

Does it make the issue clearer?


P.S. Example of a localStorage declaration as an extern:

/**
 * @const
 */
function localStorage() {}
/**
 * @param {string} name
 * @param {string} value
 * @return {undefined}
 */
localStorage.setItem = function(name, value) {}
/**
 * @param {string} name
 * @return {undefined}
 */
localStorage.removeItem = function(name) {}
/**
* @param {string} name
* @return {string}
*/
localStorage.getItem = function(name) {}
1reaction
ChadKillingsworthcommented, May 7, 2017

No it’s the other way around. All global externs are added to the window object if they don’t exist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ExtJS localstorage proxy model/store issue - Stack Overflow
I'm using ExtJS 5.1.0 and running into a strange problem. I have the following model:
Read more >
Window.localStorage - Web APIs | MDN
The localStorage read-only property of the window interface allows you to access a Storage object for the Document's origin; the stored data ...
Read more >
local-storage-proxy - npm
A proxy for accessing localstorage as an object. ... Start using local-storage-proxy in your project by running `npm i local-storage-proxy`.
Read more >
How to get/set cookies, sessionStorage and localStorage in ...
In this post, I will show you how to use Agenty's scraping agent to get/set cookies, sessionStorage and localStorage using Puppeteer and Chromium...
Read more >
JavaScript Proxy with Storage - David Walsh Blog
Whether it's sessionStorage , localStorage , or IndexedDB, you can use a proxy to make the API much easier to work with!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found