Angular i18n在将应用推送到Google App Engine生产环境时无法正常工作。

huangapple go评论69阅读模式
英文:

Angular i18n not working when pushing to production on Google App Engine

问题

我遇到了一个使用 Angular 应用程序的问题,该应用程序使用 i18n 进行国际化。当在本地进行服务时,应用程序运行得非常正常,但是当我将其部署到 Google App Engine 上时,出现了问题。

具体来说,我的 JavaScript 和 CSS 文件没有被正确加载,错误消息显示服务器响应的 MIME 类型为 "text/html"。以下是我看到的确切错误消息:

无法加载模块脚本:期望 JavaScript 模块脚本,但服务器响应的 MIME 类型为 "text/html"。根据 HTML 规范,模块脚本强制执行严格的 MIME 类型检查。

这是我的 app.yaml 配置:

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /assets/i18n
  static_dir: dist/nordwebb/assets/i18n
- url: /(.*\.json)
  mime_type: application/json
  static_files: dist/nordwebb/
  upload: dist/nordwebb/.*\.json$
- url: /(.*\.css)
  mime_type: text/css
  static_files: dist/nordwebb/
  upload: dist/nordwebb/.*\.css$
- url: /(.*\.js)
  mime_type: application/javascript
  static_files: dist/nordwebb/
  upload: dist/nordwebb/.*\.js$
- url: /.*
  static_files: dist/nordwebb/index.html
  upload: dist/nordwebb/index.html

skip_files:
- e2e/
- node_modules/
- src/
- coverage/
- ^(.*/)?\..*$
- ^(?!.*assets/i18n/.*\.json$).*\.json$
- ^(.*/)?.*\.md$
- ^(.*/)?.*\.yaml$
- ^LICENSE

非常感谢任何帮助。

英文:

I'm experiencing an issue with an Angular application that uses i18n for internationalization. The application works perfectly fine when serving it locally, but I encounter problems when pushing it to production on Google App Engine.

Specifically, my JavaScript and CSS files are not being loaded correctly, with the error message indicating that the server responded with a MIME type of "text/html". Here are the exact error messages I'm seeing:

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.

Here is my app.yaml configuration:

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /assets/i18n
  static_dir: dist/nordwebb/assets/i18n
- url: /(.*\.json)
  mime_type: application/json
  static_files: dist/nordwebb/
  upload: dist/nordwebb/.*\.json$
- url: /(.*\.css)
  mime_type: text/css
  static_files: dist/nordwebb/
  upload: dist/nordwebb/.*\.css$
- url: /(.*\.js)
  mime_type: application/javascript
  static_files: dist/nordwebb/
  upload: dist/nordwebb/.*\.js$
- url: /.*
  static_files: dist/nordwebb/index.html
  upload: dist/nordwebb/index.html

skip_files:
- e2e/
- node_modules/
- src/
- coverage/
- ^(.*/)?\..*$
- ^(?!.*assets/i18n/.*\.json$).*\.json$
- ^(.*/)?.*\.md$
- ^(.*/)?.*\.yaml$
- ^LICENSE

Any help would be greatly appreciated.

答案1

得分: 0

这不起作用的原因是,因为在推送到生产环境时,我跳过了所有的JSON文件,这使得我的i18n完全崩溃了。我在app.yaml中移除了JSON跳过,并且它正常工作了。

英文:

The reason why this did not work was because I was skipping all the JSON files when pushing to production which made my i18n completly break. I removed the JSON skip under the app.yaml and it worked fine.

huangapple
  • 本文由 发表于 2023年6月13日 00:28:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76458592.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定