[Original] Knowing the root and knowing the bottom and thoroughly solving expected a JavaScript module script but the server responded with a MIME type of "t......

I built a vue project compiled by vite. After building, I reported an error. I was puzzled. A bunch of answers on the Internet led me to the pit. They were all wrong. At least I was prompted that the file could not be loaded. Click on this wrong file, it can be loaded.

If you go to Baidu, you will be taken to the pit,
but the problem points to nginx, in fact, it is a configuration problem of nginx

For example, this article http://m.pcxitongcheng.com/server/anz/2022-11-16/33023.html
I think it has nothing to do with this, because the files that cannot be loaded above can be opened,
and there are some answers say so

server {
    listen 80;
    server_name your_domain.com;  # 替换成你的域名或IP地址

    root /path/to/your/website;   # 替换成你的网站目录的实际路径

    location / {
        autoindex on;  # 开启自动索引
        index index.html index.htm;  # 设置索引文件的优先顺序
    }

    # 其他的配置项...
}

So I used my own file server and finally verified that the problem was caused by nginx,
but I didn’t use the secondary directory here, which is not the solution to those answers on the Internet

111

Why do I think it's nginx's problem? It's not very complicated to configure what to configure index. Configure
or configure like this

location / {
  try_files $uri $uri/ /index.html;
}

Even
check in the vite.confg.ts of the vue projectbase: './',

Or /
, however, every file of mine can be opened, and the answers on this website are not. After comparing, I found that all files can be accessed, and it is exactly the same as the code of my own server that can be accessed, so I suddenly realized.

Solution:

Guess you like

Origin blog.csdn.net/u010042660/article/details/132079449