Skip to content

Cannot use import statement outside a module #78

Open

Description

@SyntaxSamurai43

If I just add this code, it gives the error "Cannot use import statement outside a module"
What am I doing wrong?
See the code here: https://jsfiddle.net/4gvwatLn/

<script type="module" src="https://unpkg.com/rough-notation?module"></script>

<script>
import { annotate } from 'rough-notation';
// Or using unpkg
// import { annotate } from 'https://unpkg.com/rough-notation?module';

const e = document.querySelector('#myElement');
const annotation = annotate(e, { type: 'underline' });
annotation.show();
</script>

Activity

  1. iamjenny commented on Jun 27, 2023

    @iamjenny

    import { annotate } from 'rough-notation'; is an import statement. The <script> needs to be <script type="module"> for code that uses import.

    Since you're using the link, you'll want to use the unpkg syntax below, the import { annotate } from 'https://unpkg.com/rough-notation?module';

    If you delete your first line, add type module to the script tag, and use the second import commented out, the fiddle starts to work :)

    Commenting here because I went through the exact same experience and came to this realization.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions