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

Specifying dependencies for intermediary packages #199

Open
x-yuri opened this issue Nov 1, 2021 · 2 comments
Open

Specifying dependencies for intermediary packages #199

x-yuri opened this issue Nov 1, 2021 · 2 comments

Comments

@x-yuri
Copy link

x-yuri commented Nov 1, 2021

Consider the following page:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap">
    <script type="module">
        import React from 'https://esm.sh/react@17.0.0?dev';
        import ReactDOM from 'https://esm.sh/react-dom@17.0.0?dev';
        import TextField from 'https://esm.sh/@material-ui/core@4.12.3/TextField?deps=react@17.0.0,react-dom@17.0.0&dev';
        import Button from 'https://esm.sh/@material-ui/core@4.12.3/Button?deps=react@17.0.0,react-dom@17.0.0&dev';

        const e = React.createElement;

        ReactDOM.render(
            // e(Button, {variant: 'contained', color: 'primary'}, 'Button'),
            e(TextField),
            document.getElementById('root')
        );
    </script>
</head>
<body>
    <div id="root"></div>
</body>
</html>

It fails with:

Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
    See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

On one hand:

https://esm.sh/react@17.0.0?dev
https://cdn.esm.sh/v55/react@17.0.0/es2015/react.development.js

On the other:

https://esm.sh/@material-ui/core@4.12.3/TextField?deps=react@17.0.0,react-dom@17.0.0&dev
https://cdn.esm.sh/v55/@material-ui/core@4.12.3/X-ZGVwczpyZWFjdC1kb21AMTcuMC4wLHJlYWN0QDE3LjAuMA/es2015/TextField.development.js
https://cdn.esm.sh/v55/react-transition-group@4.4.2/es2021/react-transition-group.development.js
https://cdn.esm.sh/v55/react@17.0.2/es2021/react.development.js

The same with @mui/material:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap">
    <script type="module">
        import React from 'https://esm.sh/react@17.0.0?dev';
        import ReactDOM from 'https://esm.sh/react-dom@17.0.0?dev';
        import TextField from 'https://esm.sh/@mui/material@5.0.6/TextField?dev&deps=react@17.0.0,react-dom@17.0.0';
        import Button from 'https://esm.sh/@mui/material@5.0.6/Button?dev&deps=react@17.0.0,react-dom@17.0.0';

        const e = React.createElement;

        ReactDOM.render(
            // e(Button, {variant: 'contained', color: 'primary'}, 'Button'),
            e(TextField),
            document.getElementById('root')
        );
    </script>
</head>
<body>
    <div id="root"></div>
</body>
</html>

As a result we get multiple versions of React on the page and it fails. Doesn't it make sense to propagate the deps parameter? Or provide a way to specify resolutions for intermediary dependencies?

@x-yuri
Copy link
Author

x-yuri commented Nov 2, 2021

Additionally it may fail for another reason, let's say we're importing again react and mui:

import React from 'https://esm.sh/react?dev';
import TextField from 'https://esm.sh/@mui/material/TextField?dev';

But right now react resolves to:

https://cdn.esm.sh/v56/react@17.0.2/es2021/react.development.js

And mui:

https://cdn.esm.sh/v55/@mui/material@5.0.6/es2021/TextField.development.js
https://cdn.esm.sh/v55/react-transition-group@4.4.2/es2021/react-transition-group.development.js
https://cdn.esm.sh/v55/react@17.0.2/es2021/react.development.js

P.S. And right now the index page doesn't work:

Uncaught (in promise) SyntaxError: import not found: default

Triggered by https://esm.sh/embed/index.js:2:

import marked from "/marked";

Apparently because marked@4.0.0 was just released.

@snendev
Copy link

snendev commented Jan 31, 2022

fyi, i believe this is the same issue as reported in #165

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

No branches or pull requests

2 participants