解决托管在 Google App Engine 上的 Angular 项目的 MIME 类型问题
Resolving mime type issues for Angular project hosted on Google App Engine
我刚刚将我的 Angular (8) 项目部署到 Google App Engine,有时我的网站会加载,而其他时候我会遇到此错误: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.
我可以'没有弄清楚模式是什么,为什么看起来不错然后放弃。
出现这些文件的错误消息:
runtime-es2015.cdfb0ddb511f65fdc0a0.js
polyfills-es2015.ffa9bb4e015925544f91.js
main-es2015.10e52dfadb49c8bec6fe.js
万一它是相关的,当我加载它时,我遇到了类似于 的情况,即登录页面以外的页面不会在刷新时重新加载。
我的app.yaml:
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /(.*)
static_files: dist/build/index.html
upload: dist/build/index.html
- url: /
static_dir: dist/build
- url: /(.*\.js)$
secure: always
static_files: dist/build/
upload: dist/build/.*\.js$
mime_type: application/javascript
skip_files:
- e2e/
- node_modules/
- src/
- coverage
- ^(.*/)?\..*$
- ^(.*/)?.*\.json$
- ^(.*/)?.*\.md$
- ^(.*/)?.*\.yaml$
- ^LICENSE
有什么想法吗?
尝试删除 app.yaml
中的 mime_type: application/javascript
,然后在第一个处理程序中添加文件扩展名,以防您的应用使用更多文件。
样本app.yaml:
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /(.*\.(gif|png|jpg|less|json|woff|woff2|ttf|eot|scss|css|js|ico|svg)(|\.map))$
static_files: dist/build/index.html
upload: dist/build/index.html
- url: /(.*)
static_files: dist/index.html
upload: dist/index.html
skip_files:
- e2e/
- node_modules/
- src/
- coverage
- ^(.*/)?\..*$
- ^(.*/)?.*\.json$
- ^(.*/)?.*\.md$
- ^(.*/)?.*\.yaml$
- ^LICENSE
我刚刚将我的 Angular (8) 项目部署到 Google App Engine,有时我的网站会加载,而其他时候我会遇到此错误: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.
我可以'没有弄清楚模式是什么,为什么看起来不错然后放弃。
出现这些文件的错误消息:
runtime-es2015.cdfb0ddb511f65fdc0a0.js
polyfills-es2015.ffa9bb4e015925544f91.js
main-es2015.10e52dfadb49c8bec6fe.js
万一它是相关的,当我加载它时,我遇到了类似于
我的app.yaml:
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /(.*)
static_files: dist/build/index.html
upload: dist/build/index.html
- url: /
static_dir: dist/build
- url: /(.*\.js)$
secure: always
static_files: dist/build/
upload: dist/build/.*\.js$
mime_type: application/javascript
skip_files:
- e2e/
- node_modules/
- src/
- coverage
- ^(.*/)?\..*$
- ^(.*/)?.*\.json$
- ^(.*/)?.*\.md$
- ^(.*/)?.*\.yaml$
- ^LICENSE
有什么想法吗?
尝试删除 app.yaml
中的 mime_type: application/javascript
,然后在第一个处理程序中添加文件扩展名,以防您的应用使用更多文件。
样本app.yaml:
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /(.*\.(gif|png|jpg|less|json|woff|woff2|ttf|eot|scss|css|js|ico|svg)(|\.map))$
static_files: dist/build/index.html
upload: dist/build/index.html
- url: /(.*)
static_files: dist/index.html
upload: dist/index.html
skip_files:
- e2e/
- node_modules/
- src/
- coverage
- ^(.*/)?\..*$
- ^(.*/)?.*\.json$
- ^(.*/)?.*\.md$
- ^(.*/)?.*\.yaml$
- ^LICENSE