Angular 服务器端渲染的一个错误消息 - No provider for InjectionToken REQUEST
错误消息:
NullInjectorError: R3InjectorError(AppServerModule)
WindowRef -> InjectionToken SERVER_REQUEST_URL -> InjectionToken SERVER_REQUEST_URL -> InjectionToken SERVER_REQUEST_URL -> InjectionToken REQUEST]:
NullInjectorError: No provider for InjectionToken REQUEST!
Angular universal engine 的文档:
https://github.com/angular/universal/tree/master/modules/express-engine
服务器端的 HTTP request 调用,通过 Injection token
注入到 SSR Application 里:
import { Request } from 'express';
import { REQUEST } from '@nguniversal/express-engine/tokens';@Injectable()
export class RequestService {constructor(@Inject(REQUEST) private request: Request) {}
}
这个 token 在客户端环境下不可用。
相关错误:https://github.com/angular/universal-starter/issues/423
https://gitter.im/angular/universal/archives/2018/06/17
REQUEST and RESPONSE won’t exist when you run in the browser context, even when you are running the SSR server
Use @Optional and take care to check whether you’ve got it, and consider using isServerPlatform to detect when you are running on the server side
在浏览器上下文环境运行时,REQUEST 和 RESPONSE 不可用。使用 @Optional
来避免 NullInjectorError 错误,以及使用 isServerPlatform
检测当前的运行环境。
相关 issue:https://github.com/SAP/spartacus/issues/11016
The SERVER_REQUEST_ORIGIN and SERVER_REQUEST_URL should not be provided in CSR by design.
SERVER_REQUEST_ORIGIN
在文件 ssr-providers.ts
里提供实现:
Angular 服务器端渲染的一个错误消息 - No provider for InjectionToken REQUEST相关推荐
- Angular开发遇到的一个错误消息 - Expected linebreak to be LF(和本地文件的换行设置有关)
(linebreak-style)tslint(1) 命令: ng test core --code-coverage console会不定期打印出单元测试执行结果: 最后2554个全部执行完毕. 在 ...
- Angular compiler报的一个错误消息:Component XX is not part of any NgModule
Error in /turbo_modules/@angular/compiler@9.1.12/bundles/compiler.umd.js (29363:23) Component Produc ...
- Angular单元测试的一个错误消息
错误消息: 'expect' was used when there was no current spec, this could be because an asynchronous test t ...
- Angular 服务器端渲染的学习笔记(一)
官网链接:https://angular.io/guide/universal Angular Universal, a technology that renders Angular applica ...
- Angular 服务器端渲染的学习笔记(二)
官网地址:https://angular.io/guide/universal I have mainly used angular universal for SEO purposes. In th ...
- 使用Java消费API的一个错误消息PKIX path building failed以及解决方案
我使用Java代码消费一个网站的Restful API,遇到如下错误: PKIX path building failed: sun.security.provider.certpath.SunCer ...
- Angular依赖注入机制的一个错误消息:Error Cannot instantiate cyclic dependency!
例子: import { Injectable } from '@angular/core';@Injectable({providedIn: 'root',}) export abstract cl ...
- JDK安全证书的一个错误消息 No subject alternative names present的解决办法
我使用Java消费某网站一个Restful API时,遇到这个错误: 21:31:16.383 [main] DEBUG org.springframework.web.client.RestTemp ...
- SAP OData 服务在 gateway 层出错,应该如何处理?通过一个错误消息 Query XXX is invalid or contains errors 来举例说明
在浏览器里访问如下url遇到错误: https://jerry.sap.corp:44300/sap/opu/odata/sap/C_SALESCONTRACTITMFLFMTQ_CDS/$metad ...
最新文章
- 自定义 Spring Boot Starter
- 网易视频云分享:如何搭建视频转码集群
- 编写高质量代码:改善Java程序的151个建议(第3章:类、对象及方法___建议36~40)
- Java是发展的垫脚石。 学习吧!
- Exchange系列之exchange2003sp2部署
- MATLAB 不能保存变量问题及解决办法
- MVC学习Day01
- finedb(内置的HSQL数据库)迁移数据到MySQL
- python爬虫实例项目大全-GitHub 上有哪些优秀的 Python 爬虫项目?
- docker添加加速器
- 向量表示 运动抛物线_黄老师讲数学(460)向量、数列、双变量、坐标计算、极限等结合的一道题...
- cpu飙高1000,几近崩溃
- win11一直弹出用户账户控制怎么解决
- requests、xpath应用案例
- 实验六、contentprovider实验+SQLite数据库的实现
- 研究了一堆英语学习软件,发现了一个美国宝藏口语App,国内也能用!
- 2018年计算机考证时间
- phpstorm注册码 激活 授权码 License server
- java解析excel合并单元格,100%好评!
- Python的七大就业方向,小白适合哪个方向?学了Python能干什么?
热门文章
- 查询缓存---Mybatis学习笔记(十)
- android开发常用的颜色值
- OCP笔记部分整理-学习参考
- shell脚本:lvs启动简易脚本
- 转载:使用sklearn进行数据挖掘
- js中创建form表单
- servlet会话技术
- Wordcount on YARN 一个MapReduce示例
- 【题解】 P2151 [SDOI2009]HH去散步
- pyemd资料学习 2019.1.24 https://media.readthedocs.org/pdf/pyemd/latest/pyemd.pdf