V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
jahnsli
V2EX  ›  NGINX

vue3 vite3 gzip 提示 Failed to load module script

  •  
  •   jahnsli · 2023-01-02 23:29:32 +08:00 · 1510 次点击
    这是一个创建于 697 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/html”. Strict MIME type checking is enforced for module scripts per HTML spec

    这是 nginx 配置

    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include mime.types;
        default_type application/octet-stream;
        server_names_hash_bucket_size 3526;
        server_names_hash_max_size 4096;
        log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
        '$host "$request_uri" $status'
        '"$http_referer" "$http_user_agent"';
        sendfile on;
        tcp_nopush on;
        keepalive_timeout 300;
        client_header_timeout 3m;
        client_body_timeout 3m;
        send_timeout 3m;
        connection_pool_size 256;
        client_header_buffer_size 16k;
        large_client_header_buffers 8 4k;
        request_pool_size 4k;
        output_buffers 4 32k;
        postpone_output 1460;
        client_max_body_size 100m;
        client_body_buffer_size 256k;
        fastcgi_intercept_errors on;
        tcp_nodelay on;
        gzip on; 
        gzip_buffers 4 16k;
        gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;
    
        upstream serveraddress{
            server *****:8100;
        }
    
        server { 
            listen       8080;
            root   /usr/local/nginx/html/dist;
            index index.html;
            location / {       
                    try_files $uri $uri/ @router;
                 index index.html;
                  proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }  
    
            location @router {
                rewrite ^.*$ /index.html last;
            }
    
            location ~^/apis/{
                    rewrite ^/apis/(.*)$ /$1 break;
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_pass http://serveraddress; 
            proxy_read_timeout 300s;
            proxy_send_timeout 300s;
            }  
        }
    }
    
    
    2 条回复    2023-01-03 16:25:02 +08:00
    weixiangzhe
        1
    weixiangzhe  
       2023-01-03 14:24:59 +08:00
    1. 就是网络加载失败了,加个路由加载失败处理就好
    2. 对应的还有,你开启了全局的 http cache ,这样的话,每次发版后,旧用户访问加载失败的概率非常高,建议是 html 文件只开启 协商缓存就好了, 我们的配置类似这样

    ```
    # static resources
    location ^~ /assets/ {
    expires 1M;
    access_log off;
    add_header Cache-Control "public";
    }

    # html 文件
    location / {
    add_header Cache-Control "no-cache, max-age=0";
    }
    ```
    jahnsli
        2
    jahnsli  
    OP
       2023-01-03 16:25:02 +08:00
    但是我隔了好久也是提示

    Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/html”. Strict MIME type checking is enforced for module scripts per HTML spec
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2812 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 07:47 · PVG 15:47 · LAX 23:47 · JFK 02:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.