Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS express not serving ES6 javascript modules

I started using ES6 javascript modules in my ASP.NET MVC application but IIS express is refusing to serve javascript file of type module in script tag. I'm getting 401 Unauthorized.

<script src="~/Scripts/index.js" type="module"></script>

When i remove type="module" from script tag then it works fine.

Are request filters involved? Can you please help me set them right?

like image 385
Peracek Avatar asked Jan 30 '18 13:01

Peracek


1 Answers

I ran into the same issue in a pretty bare-bones Apache setup for personal use. I was pretty dumbfounded until I came across this.

Check out the small section titled "Server Considerations", which mentions the use of crossorigin="use-credentials" in the <script> tag. It sounded only vaguely relevant since I'm working exclusively on a local origin, but I had nothing else to go on so tried it on a whim and it worked.

I can't pretend to understand why, or speak to any unintended consequences, so I would suggest diving into those aspects before pasting this into deployment.

like image 82
formula-hunter Avatar answered Oct 04 '22 01:10

formula-hunter