Skip to content

Edge won't parse JS code that uses import.meta.url #8251

@mramato

Description

@mramato
Contributor

We use import.meta.url in buildModuleUrl to find the current module location and build CESIUM_BASE_URL. Apparently Edge won't even parse code with import.meta.url in it and silently fails without any kind of indication.

We may be able to avoid import.meta.url completely and take a different approach.

There's some other weirdness in buildModuleUrl as well that we may want to review since a lot has changed since it was written.

Activity

mramato

mramato commented on Oct 3, 2019

@mramato
ContributorAuthor

This only affects the unbuilt versions of Cesium Viewer and Sandcastle on Edge. Built versions work as expected.

The main issue is that we ship the unbuilt versions in the Cesium release zip, the hosted versions on cesiumjs.org work fine.

hpinkos

hpinkos commented on Oct 15, 2019

@hpinkos
Contributor

@mramato is this something you're going to take care of?

mramato

mramato commented on Oct 16, 2019

@mramato
ContributorAuthor

I've looked into it, but at first glance Edge looks to be in worse shape than I thought. I was thinking of addressing this by having the Sandcastle we ship with Cesium always use CesiumUnminified instead of the built version, which would make it faster and work in Edge too (which is the only browser it currently has problems with).

hpinkos

hpinkos commented on Oct 22, 2019

@hpinkos
Contributor

@mramato Should this still be marked next-release? What's the plan?

added a commit that references this issue on Oct 24, 2019
4741df6
thw0rted

thw0rted commented on Jan 26, 2021

@thw0rted
Contributor

To those watching: did you ever wind up digging into ways to work around the SyntaxError? I was just reading over webpack/webpack#7353 which talks about https://webpack.js.org/guides/asset-modules/#url-assets.

The short version is that Webpack is able to statically analyze new URL("./somefile.ext", import.meta.url) and magically add the correct file to the bundle. They're recommending it as a path forward for libraries to reference their own assets in a fully cross platform way, which will work whether the module is included via a <script type="module"> tag directly, imported from a consumer that's run through a bundler (well, Webpack 5+ at least), or in Node as MJS, all using the same code.

This issue actually means there's two problems: this one, i.e. writing a polyfill/fallback that avoids the SyntaxError, and also the root cause of #8401, which is that the way Cesium handles asset references has too much indirection to support static analysis. I'm also commenting over there to explain what I mean by that.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @thw0rted@mramato@hpinkos

      Issue actions

        Edge won't parse JS code that uses import.meta.url · Issue #8251 · CesiumGS/cesium