Skip to content

Just a question #296

@neilyoung

Description

@neilyoung
<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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions