Lazy Loaded Modules with AOT - TypeError: '' is not a function when served from NGINX

眉间皱痕 提交于 2019-12-05 07:35:52

It's because when you use AOT, the code is uglified with some funny UTF-8 symbols; ɵ in i0.ɵcrt in your case

You need to tell nginx to use UTF-8 charset

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name _;

  charset UTF-8; #<==== Add this

Replace your current nginx.conf file in the /etc/nginx folder with the following,

#worker_processes 2;

events {
    worker_connections 1024;
}
http {
   sendfile on;

   gzip on;
   gzip_disable "msie6";

   gzip_vary on;
   gzip_proxied any;
   gzip_comp_level 6;
   gzip_buffers 16 8k;
   gzip_http_version 1.1;
   gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    log_format timed_combined '$remote_addr - $remote_user [$time_local] '
    '"$request" $status $body_bytes_sent '
    '"$http_referer" "$http_user_agent" '
    '$request_time $upstream_response_time $pipe';

    access_log /var/log/nginx/access.log timed_combined;
    error_log /var/log/nginx/error.log;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    server {
        listen 80;
        server_name _;
        return 404;
    }

   server {
        listen 80;
        server_name www.example.com;

        location / {
           root /home/pokusr/propok-frontend/dist;
           try_files $uri /index.html;
        }
        location ~* "^/[a-z0-9]{40}.(css|js)$" {
            root /home/usr/proj_path/dist/;
            access_log off;
            expires max;
        }
    }
}

Lazy loaded routes will have the hash values in it and location ~* "^/[a-z0-9]{40}.(css|js)$" { this will solve the problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!