Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to load module script:Expected a JavaScript module script but the server responded with a MIME type of "text/plain".Strict MIME type checking is enforced for module script per HTML spec. #4734

Closed
caesarding07 opened this issue Apr 27, 2022 · 8 comments
Labels
invalid ❓ This doesn't seem right

Comments

@caesarding07
Copy link

Windows 11
Node v16.14.2
Vue 3.2.25
Vite 2.9.5

while I use the caddy to get my static file up and just run the HelloWorld, it catches an error that is like this

Fail to load module script:Expected a JavaScript module script but the server responded with a MIME type of "text/plain".Strict MIME type checking is enforced for module script per HTML spec.

what's more, I also try it with Nginx, and it run ok.

@mohammed90
Copy link
Member

Thank you for the report/question! Ideally, we need to be able to reproduce the bug in the most minimal way possible. This allows us to write regression tests to verify the fix is working. If we can't reproduce it, then you'll have to test our changes for us until it's fixed -- and then we can't add test cases, either.

I've attached a template below that will help make this easier and faster! This will require some effort on your part -- please understand that we will be dedicating time to fix the bug you are reporting if you can just help us understand it and reproduce it easily.

This template will ask for some information you've already provided; that's OK, just fill it out the best you can. 👍 I've also included some helpful tips below the template. Feel free to let me know if you have any questions!

Thank you again for your report, we look forward to resolving it!

Template

## 1. Environment

### 1a. Operating system and version

```
paste here
```


### 1b. Caddy version (run `caddy version` or paste commit SHA)

```
paste here
```


### 1c. Go version (if building Caddy from source; run `go version`)

```
paste here
```


## 2. Description

### 2a. What happens (briefly explain what is wrong)




### 2b. Why it's a bug (if it's not obvious)




### 2c. Log output

```
paste terminal output or logs here
```



### 2d. Workaround(s)




### 2e. Relevant links




## 3. Tutorial (minimal steps to reproduce the bug)




Helpful tips

  1. Environment: Please fill out your OS and Caddy versions, even if you don't think they are relevant. (They are always relevant.) If you built Caddy from source, provide the commit SHA and specify your exact Go version.

  2. Description: Describe at a high level what the bug is. What happens? Why is it a bug? Not all bugs are obvious, so convince readers that it's actually a bug.

    • 2c) Log output: Paste terminal output and/or complete logs in a code block. DO NOT REDACT INFORMATION except for credentials.
    • 2d) Workaround: What are you doing to work around the problem in the meantime? This can help others who encounter the same problem, until we implement a fix.
    • 2e) Relevant links: Please link to any related issues, pull requests, docs, and/or discussion. This can add crucial context to your report.
  3. Tutorial: What are the minimum required specific steps someone needs to take in order to experience the same bug? Your goal here is to make sure that anyone else can have the same experience with the bug as you do. You are writing a tutorial, so make sure to carry it out yourself before posting it. Please:

    • Start with an empty config. Add only the lines/parameters that are absolutely required to reproduce the bug.
    • Do not run Caddy inside containers.
    • Run Caddy manually in your terminal; do not use systemd or other init systems.
    • If making HTTP requests, avoid web browsers. Use a simpler HTTP client instead, like curl.
    • Do not redact any information from your config (except credentials). Domain names are public knowledge and often necessary for quick resolution of an issue!
    • Note that ignoring this advice may result in delays, or even in your issue being closed. 😞 Only actionable issues are kept open, and if there is not enough information or clarity to reproduce the bug, then the report is not actionable.

Example of a tutorial:

Create a config file:
{ ... }

Open terminal and run Caddy:

$ caddy ...

Make an HTTP request:

$ curl ...

Notice that the result is ___ but it should be ___.

@mohammed90 mohammed90 added the needs info 📭 Requires more information label Apr 27, 2022
@caesarding07
Copy link
Author

1. Environment

1a. Operating system and version

Windows 11  22H2 22598.1

1b. Caddy version (run caddy version or paste commit SHA)

v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=

2. Description

2a. What happens (briefly explain what is wrong)

After I run caddy file-server,the browser catch a error like this:

Fail to load module script:Expected a JavaScript module script but the server responded with a MIME type of "text/plain".Strict MIME type checking is enforced for module script per HTML spec

2b. Why it's a bug (if it's not obvious)

it can run ok if i use nginx。

2c. Log output

nothing terminal output or logs here

2d. Workaround(s)

2e. Relevant links

3. Tutorial (minimal steps to reproduce the bug)

I see the js Content-Type is text/plain while text/javascript is right.

@francislavoie
Copy link
Member

You didn't give us the information we need.

What file are you trying to serve? Give an example request with curl -v and its output.

@caesarding07
Copy link
Author

I have solve it. I add header /*.js Content-Type text/javascript into the Caddyfile.
However,I still think it is a bug of caddy. Because I can get it up on my Mac normally while catch error on the windows.😁😁😁
The Last but not least, I'm so sorry that you may not understand what i taking about because of my poor Engish.

@francislavoie
Copy link
Member

We have no evidence of a bug. This works fine for us.

It's probably a misconfiguration in your environment. Go pulls mime type mappings from the operating system, so if it's not correctly set on your system, then it won't serve the right content type.

I'm guessing you might be running into this: golang/go#32350, there's an old workaround repo: https://github.com/zekroTJA/go-win-mime-fix

@francislavoie francislavoie added invalid ❓ This doesn't seem right and removed needs info 📭 Requires more information labels Apr 27, 2022
@caesarding07
Copy link
Author

Sorry, I just want to use caddy serve the Vue template which is built by Vite.It's a HelloWorld. I would show you the photo if you
dont understand me.

This is the error the browse catch!

This is the page I what to serve!

By the way, I can serve the page correctlly on my Mac.

@caesarding07
Copy link
Author

Go pulls mime type mappings from the operating system, so if it's not correctly set on your system, then it won't serve the right content type.

Maybe you are right,I havent install the go on my Windows.I will tyr it! Thank you so much!💕💕💕💕

@francislavoie
Copy link
Member

This does not have to do with installing Go on your Windows machine.

Caddy is written with Go, and it uses Go's stdlib mime-types implementation.

If your Windows machine isn't correctly configured to map *.js to text/javascript, then Caddy won't serve that mime type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid ❓ This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants