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

Cannot use import statement outside a module #78

Open
Bobolinos opened this issue Apr 16, 2023 · 1 comment
Open

Cannot use import statement outside a module #78

Bobolinos opened this issue Apr 16, 2023 · 1 comment

Comments

@Bobolinos
Copy link

Bobolinos commented Apr 16, 2023

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>
@iamjenny
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants