Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to import - lodash #937

Open
Kreijstal opened this issue Nov 27, 2024 · 5 comments
Open

Failed to import - lodash #937

Kreijstal opened this issue Nov 27, 2024 · 5 comments
Labels
browser Not working in Browser

Comments

@Kreijstal
Copy link

Kreijstal commented Nov 27, 2024

Failing module

  let { Workbook } = await import(
    "https://esm.sh/@fortune-sheet/react?deps=react@18,react-dom@18"
  );
  let root = document.createElement("div");
  ReactDOM.render(
    React.createElement(Workbook, { data: [{ name: "Sheet1" }] }),
    root
  );

Error message

After onload I got this:

TypeError: (intermediate value).values is not a function

Additional info

  • Browser info: firefox

So the issue is the following, module imports https://esm.sh/v135/[email protected]/es2022/lodash.mjs which conditionally checks if Window is defined, if it is, instead of exporting Loadsh, it exports an empty object, and writes _ on "window". Of course since esm.sh rewrites _ into R, R becomes an object, so it attempts to call R.values, which is not a function..

demo

@Kreijstal Kreijstal added the browser Not working in Browser label Nov 27, 2024
@Kreijstal
Copy link
Author

Is there a way to substitute a dependency, aka lodash-es for lodash?

@knoxnoe
Copy link

knoxnoe commented Nov 28, 2024

image

it's look ok? @Kreijstal

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Demo</title>
    <script type="module" async>
      import React from "https://esm.sh/react@18";
      import ReactDOM from "https://esm.sh/react-dom@18";

      async function initialize() {
        let { Workbook } = await import(
          "https://esm.sh/@fortune-sheet/react?deps=react@18,react-dom@18"
        );

        console.log(Workbook);

        ReactDOM.createRoot(
          document.getElementById("root")
        ).render(
          React.createElement(Workbook, { data: [{ name: "Sheet1" }] })
        );
      }

      window.onload = initialize;
    </script>
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

@Kreijstal
Copy link
Author

@knoxnoe How did you manage to make it work? when using ReactDOM I get an error using firefox, does it work for you on this website as well? https://observablehq.com/d/37ef873372b7f3e4

@knoxnoe
Copy link

knoxnoe commented Nov 29, 2024

@knoxnoe How did you manage to make it work?

copy this code in an *.html file,and then open it in your local browser

when using ReactDOM I get an error using firefox, does it work for you on this website as well? https://observablehq.com/d/37ef873372b7f3e4

i'll take a look later

@Kreijstal
Copy link
Author

@knoxnoe How did you manage to make it work?

copy this code in an *.html file,and then open it in your local browser

when using ReactDOM I get an error using firefox, does it work for you on this website as well? https://observablehq.com/d/37ef873372b7f3e4

i'll take a look later

also use the following css @fortune-sheet/react/dist/index.css

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser Not working in Browser
Projects
None yet
Development

No branches or pull requests

2 participants