Skip to content
← Back to Community
Modules
Profile icon
dfnk

Why is this not working? When importing?

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
MANAV0201
Profile icon
dfnk
Comments
hotnewtop
Profile icon
Coder100

Hello, right now the script tag is not a module.

Fix

<script type="module"></script>

Adding type="module" will fix this. Happy coding!

Profile icon
dfnk

@Coder100 Is there a different way, I was wondering since I was using a NPM package?

Profile icon
Coder100

NPM is for the server-side. Usually, you would be using something like unpkg to get the module on the client-side. @dfnk

Profile icon
dfnk

@Coder100 I has already installed the package and have seen some guides. It was just not working for me so I was wondering if my code was wrong, to import it.

Profile icon
Coder100

Looks good to me, but you are using it wrong, type="module" is for the main script using the import functions. @dfnk

Profile icon
dfnk

@Coder100 What do you mean?

Profile icon
Coder100
<script src="script.js"></script>

Replaces to

<script src="script.js" type="module"></script>

@dfnk

Profile icon
dfnk

@Coder100 By any chance could you show me a simple repl of it working?

Profile icon
Coder100

sure @dfnk

Profile icon
dfnk

@Coder100 thanks

Profile icon
Coder100

i'm working on fixing it @dfnk

Profile icon
dfnk

@Coder100 Thanks so much

Profile icon
Coder100
Profile icon
dfnk

@Coder100 What do you mean? np?

Profile icon
Coder100

no problem @dfnk

Profile icon
dfnk

@Coder100 Oh, sorry not that good at abbreviations.

Profile icon
Coder100
Profile icon
Coder100

Sorry for the time it took but I guess my browser is just being weird @dfnk

Profile icon
dfnk

@Coder100 np, thanks

Profile icon
Coder100

does it work? @dfnk