英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论