Skip to content

Flaws in ESM Build result in failure to build with Vite, Snowpack, etc. #3521

Closed

Description

@joshacheson

Issue: When including @elastic/eui in a project and using vitejs/vite or pikapkg/snowpack to build, a build fails.

Investigation so far: The best way to get a summary of investigation so far into this issue (that may or may not continue) is probably to look at this issue in vitejs/vite.

I'm filing this issue mostly for awareness, and of course don't hold any expectation that anyone investigates this, fixes it, etc. I have moved on to using CRA because the benefits of @elastic/eui outweighed the benefits of vite or snowpack for my use case.

Cheers

Activity

  1. chandlerprall commented on May 28, 2020

    @chandlerprall
    Contributor

    Thanks for reporting and cross-referencing! For completeness & transparency, we have #3437 tracking a known class of issues with EUI+CRA in development mode.

  2. chandlerprall commented on May 28, 2020

    @chandlerprall
    Contributor

    Looking through the vite issue linked above, vitejs/vite#280 (comment) has the specific details: EUI itself is ESM compatible (or is theoretically, as we've never proven that and the dynamic icon import may or may not work in a pure browser ESM context), but has cjs-only dependencies - some of which are mentioned in that comment.

  3. lemcii commented on May 30, 2020

    @lemcii

    Snowpack seems to somewhat work, with this workaround:

    var reactIs = require("react-is")
    var lodash = require("lodash")
    
    module.exports = {
      extends: "@snowpack/app-scripts-react",
      scripts: {},
      plugins: [],
      installOptions: {
        rollup: {
          namedExports: {
            "node_modules/@elastic/eui/node_modules/react-is/index.js": Object.keys(reactIs),
            "node_modules/lodash/lodash.js": Object.keys(lodash),
          },
        },
      },
    }
    

    However none of the icons want to work, I'm getting this at runtime:

    Loading module from “http://localhost:8080/web_modules/@elastic/assets/'%20+%20typeToPathMap[iconType]%20+%20'.js” was blocked because of a disallowed MIME type (“”).
    localhost:8080
    Loading failed for the module with source “http://localhost:8080/web_modules/@elastic/assets/'%20+%20typeToPathMap[iconType]%20+%20'.js”. localhost:8080:698:1
    TypeError: error loading dynamically imported module
    
  4. chandlerprall commented on Jun 1, 2020

    @chandlerprall
    Contributor

    @lemcii do you have a repo available with that setup I could test with?

  5. lemcii commented on Jun 2, 2020

    @lemcii
  6. FredKSchott commented on Jun 22, 2020

    @FredKSchott

    As of the latest Snowpack, namedExports should no longer be required thanks to an internal rollup upgrade.

  7. lemcii commented on Jun 23, 2020

    @lemcii

    Thanks, upgrade the example and removed the namedExports workaround above.

    Did have this error:

    Uncaught ReferenceError: global is not defined
        web_modules elastic/eui.js:192579
    

    Used a workaround from this issue, imagine this may be "fixed" by Snowpack later.

  8. FredKSchott commented on Jun 23, 2020

    @FredKSchott

    +1, we should be able to handle global without the need for a node polyfill plugin

  9. github-actions commented on Mar 11, 2021

    @github-actions

    👋 Hey there. This issue hasn't had any activity for 180 days. We'll automatically close it if that trend continues for another week. If you feel this issue is still valid and needs attention please let us know with a comment.

  10. added
    stale-issue
    on Mar 11, 2021
  11. balthild commented on Dec 8, 2021

    @balthild

    Hello. Why do this issue be closed? It seems the problem has not been fixed in EUI 42.0.0.

  12. aircjm commented on Dec 17, 2021

    @aircjm

    Hello. Why do this issue be closed? It seems the problem has not been fixed in EUI 42.0.0.

    +1

  13. theamanbhargava commented on Jan 11, 2022

    @theamanbhargava

    Any workarounds for this?

  14. balthild commented on Jan 11, 2022

    @balthild

    I workaround it by adding

            <script>
                globalThis.global = globalThis;
            </script>

    to somewhere before the main script.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stale-issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions