You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a Java library that is transpiled with j2cl to JavaScript, resulting in a "mylib.js". Until now, we were able to use the transpiled Java-classes and libraries as follows:
However, since a change in recent days (it seems to be this commit here: bazelbuild/rules_closure@b159f54), this kind of import does not work anymore. What now works is
We use browserify for bundling. I see now the following options:
Replace all our imports and usages with globalThis like above.
Add some post-processing for the transpiled mylib.js (most probably not future-proof)
Find some transpiler argument or config that allows imports as before.
Is globalThis the way to go now? Or is there a reasonable and future-proof way to keep our require imports (e.g. some transpiler argument?) with the given setting (browserify)? Maybe, the way we use require was never intended like this for j2cl-transpiled libraries?
bazel version 7.4.0 bazelrc (like in the samples)
build --watchfs
build --spawn_strategy=local
build --strategy=J2cl=worker
build --strategy=Closure=worker
build --strategy=Javac=worker
build --strategy=JavaIjar=local
build --strategy=JavaDeployJar=local
build --strategy=JavaSourceJar=local
build --strategy=Turbine=local
# --experimental_inprocess_symlink_creation is used to workaround the missing
# support for paths with spaces https://github.com/bazelbuild/bazel/issues/4327.
# Remove the two flags after this issue is fixed in bazel new release.
build --enable_platform_specific_config
build:macos --experimental_inprocess_symlink_creation
test --test_output=errors
# Enable Java 11
build --java_language_version=11
build --java_runtime_version=11
# Enable Java 11 for J2CL compiler itself
build --tool_java_language_version=11
build --tool_java_runtime_version=11
@gkdn. If you mean the transpiled library (above called mylib.js), then it is the one contained in bazel-bin/src/main/javascript/mylib.js after the build completed (The build command is bazel build src/main/javascript:mylib.)
When I replace goog.global = globalThis; with goog.global = this || self; and d = d || globalThis; with d = d || goog.global; (as it was previously), then the require imports works as before.
We have a Java library that is transpiled with j2cl to JavaScript, resulting in a "mylib.js". Until now, we were able to use the transpiled Java-classes and libraries as follows:
However, since a change in recent days (it seems to be this commit here: bazelbuild/rules_closure@b159f54), this kind of import does not work anymore. What now works is
We use browserify for bundling. I see now the following options:
globalThis
like above.Is
globalThis
the way to go now? Or is there a reasonable and future-proof way to keep ourrequire
imports (e.g. some transpiler argument?) with the given setting (browserify)? Maybe, the way we userequire
was never intended like this for j2cl-transpiled libraries?bazel version 7.4.0
bazelrc (like in the samples)
BUILD
lib.js
The text was updated successfully, but these errors were encountered: