虚幻 – HTML5 部署问题 ”Cannot read properties of null.”

问题

使用 UE4.23(最后一个支持 HTML5 平台的版本) 打包 HTML5 并部署到 Apache 服务器上,基本设置完成后出现错误,页面报错如下。

Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')
Uncaught TypeError: Cannot read properties of null (reading 'toLowerCase')

解决

通过 这个提问 的回答分析,是引擎在获取 Content-Type 头时获得 null 结果导致,但是查阅资料尝试设置 Content-Type 失败。最后找到 这个提问 的回答,其分析原因为默认的 .htaccess 文件不适用于现在的 Apache 服务器,需要在 .htaccess 文件添加新的规则。添加如下内容即可。

# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule "\.cssgz$" "-" [T=text/css,E=no-gzip:1]
RewriteRule "\.jsgz$" "-" [T=text/javascript,E=no-gzip:1]
RewriteRule "\.wasmgz$" "-" [T=text/javascript,E=no-gzip:1]
RewriteRule "\.datagz$" "-" [T=text/javascript,E=no-gzip:1]

UE4是成熟的商业引擎

发表回复