mariocatch mariocatch - 1 year ago 497
ASP.NET (C#) Question

"Uncaught SyntaxError: Unexpected token import" when using momentjs with ASP5/MVC6

When I try to use momentjs, installed through bower, my web app runs into the following error when the javascript file for moment is attempted to be loaded:

Uncaught SyntaxError: Unexpected token import

On this line:

import { hooks as moment, setHookCallback } from './lib/utils/hooks';

I am using ASP5, MVC6, Visual Studio 2015 Community. Couldn't find any answers to this here or on documentation from momentjs.

My script tag looks like:

<script type="text/javascript" src="~/lib/moment/src/moment.js"></script>

Answer Source

Looks like they include a built version of it already. I was using the src version, which isn't compiled. Just point to the min version and it'll be there, which is compiled.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download