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

Just a question #296

Open
neilyoung opened this issue Apr 16, 2023 · 0 comments
Open

Just a question #296

neilyoung opened this issue Apr 16, 2023 · 0 comments

Comments

@neilyoung
Copy link

<script>
    console.log($);
    alert($.capital("hridayesh"))
    $.addDOMContent("It works I think!!!")
  </script>

Indeed, that works fine. But I'm wondering, how it would have to look like, if I externalize this functionality into a separate module "index.js" at the "index.html" directory level.

I can't make the import run. Could you elaborate please?

index.js:

import capital from './dist/index_bundle.js'
alert(capital("hridayesh"))

First attempt:

index.html:

    <script src="dist/index_bundle.js"></script>
    <script src="index.js"></script>
    <!-- <script>
      console.log($)
      alert($.capital("hridayesh"))
      $.addDOMContent("Well It Works Fine!!!")
    </script> -->

Browser error:

Cannot use import statement outside a module

Second attempt:

index.html:

    <script src="dist/index_bundle.js"></script>
    <script type="module" src="index.js"></script>
    <!-- <script>
      console.log($)
      alert($.capital("hridayesh"))
      $.addDOMContent("Well It Works Fine!!!")
    </script> -->

Browser error:

The requested module './dist/index_bundle.js' does not provide an export named 'default'

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

1 participant