Ask coding questions

← Back to all posts
Modules
dfnk (32)

Why is this not working? When importing?

Answered by Coder100 (2747) [earned 5 cycles]
View Answer
Voters
dfnk (32)
Commentshotnewtop
Coder100 (2747)

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

Fix

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

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

dfnk (32)

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

Coder100 (2747)

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

dfnk (32)

@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.

Coder100 (2747)

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

Coder100 (2747)
<script src="script.js"></script>

Replaces to

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

@dfnk

dfnk (32)

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

Coder100 (2747)

i'm working on fixing it @dfnk

dfnk (32)

@Coder100 What do you mean? np?

dfnk (32)

@Coder100 Oh, sorry not that good at abbreviations.

Coder100 (2747)

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