256 Kilobytes

Answers in Scripting and Automation | By Some Guy

Published

1,038 view, 0 RAMs, and 1 comment

Tags: Scripting, JavaScript, Errors, Programming, SyntaxError

Profile Photo - Some GuySome GuyBasic Subscriber

Hi. I've been working in JavaScript a bit, and came across a SyntaxError today. It says that I have an unexpected token that is an export/import/illegal? That's a lot of terms, and I don't know what all of them mean, and how do I make it so this error doesn't show up? Thanks for your help.

Download more RAM. 🐏 ⨉ 0Posted by Some Guy 2 years ago 🕓 Posted at 13 January, 2019 06:00 AM PST

This is a debug account.

Profile Photo - UnivaUnivaAuthor

In case you get this error it might also be related to how you included the javascript file into your html page. When loading modules you have to explicitly declare those files as such. Here an example:

//module.js:
function foo(){
   return "foo";
}
var bar = "bar";
export { foo, bar };

When you include the script like this:

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

You will get the error:

Uncaught SyntaxError: Unexpected token export

You need to include the file with a type attribute set to "module":

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

And then it will work as expected and you are ready to import your module in another module:

import { foo, bar } from  "./module.js";
console.log( foo() );
console.log( bar );

Download more RAM. 🐏 ⨉ 0Posted by Univa 2 years ago 🕓 Posted at 26 May, 2019 10:46 AM PDT

Hello.

Post a New Comment

Do you like having a good time?

Register an Account

You can also login to an existing account or reset your password. All use of this site is subject to the terms of service and privacy policy.

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account

Answers— Read More

Find more related content below!