google / elemental2

Type checked access to browser APIs for Java code.
Apache License 2.0
150 stars 38 forks source link

WebStorage: Variable x declared more than once #118

Closed sgammon closed 5 years ago

sgammon commented 5 years ago

I am encountering an issue using the webstorage module. Basically, I can add it from Java in a Bazel target, but I can't add the corresponding -j2cl dependency:

BUILD.bazel for my J2CL/Elemental2 app:

package(default_visibility = ["//visibility:public"])

load("@com_google_j2cl//build_defs:rules.bzl", "j2cl_library")
load("@com_google_j2cl//build_defs:rules.bzl", "j2cl_application")
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")

java_library(
  name = "datasynclib",
  srcs = glob(["*.java"]),
  deps = [
    "//src/main/java/io/bloombox/labs/core:core",
    "@com_google_j2cl//:jsinterop-annotations",
    "@com_google_elemental2//:elemental2-core",
    "@com_google_elemental2//:elemental2-dom",
    "@com_google_elemental2//:elemental2-indexeddb",
    "@com_google_elemental2//:elemental2-webstorage",
    "@com_google_elemental2//:elemental2-promise"])

j2cl_library(
    name = "datasynclib-j2cl",
    srcs = glob(["*.java", "js/*.js"]),
    deps = [
        "//src/main/java/io/bloombox/labs/core:core-j2cl",
        "@com_google_j2cl//:jsinterop-annotations-j2cl",
        "@com_google_elemental2//:elemental2-core-j2cl",
        "@com_google_elemental2//:elemental2-dom-j2cl",
        "@com_google_elemental2//:elemental2-webstorage-j2cl",
        "@com_google_elemental2//:elemental2-promise-j2cl"])

closure_js_library(
    name = "datasync-js",
    srcs = ["extension.js"],
    deps = [":datasynclib-j2cl"])

j2cl_application(
    name = "datasync",
    entry_points = ["bloombox.extension.datasync"],
    deps = [":datasync-js"])

The above works until I add the dependency "@com_google_elemental2//:elemental2-webstorage-j2cl" to the datasynclib-j2cl target. At that point, the build breaks, and I get the following output:

ERROR: /../src/main/java/io/bloombox/labs/ext/datasync/BUILD:43:1: Compiling 20 JavaScript files to src/main/java/io/bloombox/labs/ext/datasync/datasync.js failed (Exit 1)
external/com_google_closure_compiler/externs/browser/webstorage.js:26: ERROR - Variable Storage declared more than once. First occurrence: externs.zip//webstorage.js
function Storage() {}
         ^
  ProTip: "JSC_VAR_MULTIPLY_DECLARED_ERROR" or "checkVars" or "duplicate" or "missingSourcesWarnings" can be added to the `suppress` attribute of:
  @com_google_elemental2//java/elemental2/webstorage:webstorage-externs
  Alternatively /** @suppress {duplicate} */ can be added to the source file.

external/com_google_closure_compiler/externs/browser/webstorage.js:68: ERROR - Variable WindowSessionStorage declared more than once. First occurrence: externs.zip//webstorage.js
function WindowSessionStorage() {}
         ^
  ProTip: "JSC_VAR_MULTIPLY_DECLARED_ERROR" or "checkVars" or "duplicate" or "missingSourcesWarnings" can be added to the `suppress` attribute of:
  @com_google_elemental2//java/elemental2/webstorage:webstorage-externs
  Alternatively /** @suppress {duplicate} */ can be added to the source file.

external/com_google_closure_compiler/externs/browser/webstorage.js:86: ERROR - Variable WindowLocalStorage declared more than once. First occurrence: externs.zip//webstorage.js
function WindowLocalStorage() {}
         ^
  ProTip: "JSC_VAR_MULTIPLY_DECLARED_ERROR" or "checkVars" or "duplicate" or "missingSourcesWarnings" can be added to the `suppress` attribute of:
  @com_google_elemental2//java/elemental2/webstorage:webstorage-externs
  Alternatively /** @suppress {duplicate} */ can be added to the source file.

external/com_google_closure_compiler/externs/browser/webstorage.js:106: ERROR - Variable StorageEvent declared more than once. First occurrence: externs.zip//webstorage.js
function StorageEvent() {}
         ^
  ProTip: "JSC_VAR_MULTIPLY_DECLARED_ERROR" or "checkVars" or "duplicate" or "missingSourcesWarnings" can be added to the `suppress` attribute of:
  @com_google_elemental2//java/elemental2/webstorage:webstorage-externs
  Alternatively /** @suppress {duplicate} */ can be added to the source file.

4 error(s), 0 warning(s)

INFO: Elapsed time: 1.130s, Critical Path: 0.89s
INFO: 3 processes: 3 worker.
FAILED: Build did NOT complete successfully
gkdn commented 5 years ago

Julien, i didn't look at the underlying issue but we need to make sure these targets are part of the open source CI.

sgammon commented 5 years ago

@jDramaix i am also getting this issue trying to use indexeddb. let me know if i can help you diagnose or reproduce the issue.

jDramaix commented 5 years ago

I was able to reproduce that locally. The problem comes from two different extern files provide the same externs. I'm currently working on fixing that. I'll keep you inform when it's done.

Thanks for the bug report.

sgammon commented 5 years ago

@jDramaix, this is blocking us, is there any update? thank you again for all your hard work

jDramaix commented 5 years ago

I have a fix waiting for review internally

sgammon commented 5 years ago

@jDramaix thank you :) much appreciated

sgammon commented 5 years ago

@jDramaix, i'm still getting this issue. could we potentially leave this open until your fix is merged?

jDramaix commented 5 years ago

The fix has been merged in 1d73ef3836013f37bbb87ae4abedc83e4f60e925

Are you sure you have the same issue? JsCompiler guys submitted yesterday a change in externs file that break temporary elemental at head. Theu should sync theit github repo today.

If it's the same error, could create a small project that reproduce the error ?

sgammon commented 5 years ago

@jDramaix i can pin to that commit and see if it fixes the issue. it appears the same to me but i'll report back

thank you for the update