node.js - Angular 8 服务器端渲染不适用于 Firebase
问题描述
我正在使用 Angular Universal 建立一个 Angular 8 项目,以使我的项目对 SEO 更友好。我的实际阻碍是当我想运行时npm run server:ssr
抛出与@firebase/app package
.
我在 Windows 10 机器 Angular 8 和 Firebase ^6.2.0 上运行该项目
angular.json 文件:
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/server",
"main": "src/main.server.ts",
"tsConfig": "src/tsconfig.server.json"
},
这是我收到的信息:
@firebase/app:
Warning: This is a browser-targeted Firebase bundle but it appears it is being
run in a Node environment. If running in a Node environment, make sure you
are using the bundle specified by the "main" field in package.json.
If you are using Webpack, you can specify "main" as the first item in
"resolve.mainFields":
https://webpack.js.org/configuration/resolve/#resolvemainfields
If using Rollup, use the rollup-plugin-node-resolve plugin and specify "main"
as the first item in "mainFields", e.g. ['main', 'module'].
https://github.com/rollup/rollup-plugin-node-resolve
解决方案
您使用的 firebase 包仅适用于浏览器/客户端。困扰您的代码位于服务器端。
您需要导入(和设置)firebase-admin才能在服务器端( NodeJS )上工作。
如果您对客户端和服务器使用相同的代码,请确保使用以下标志分隔客户端代码:
if( process.env.NODE_ENV === 'development') {
// client-side only code ...
}
如果您需要更多帮助,请告诉我!
推荐阅读
- java - ksql-server 拒绝启动
- c# - 与 IIS 相比,Kestrel 中的性能较慢
- corda - 未解决的参考:构建 Corda 时绑定
- json - 是否有任何 JSON 过滤器来限制 Spring REST API 中 HTTP 请求中传递的未定义属性
- ios - 带有渐变颜色的 ImageView 的圆角问题
- sql - PostgreSQL 如何处理 1 + n 查询?
- linux - git commit 时出现“文件读取后已更改!!!”
- html - 使用css网格时如何扩展最后一行项目以适合行宽
- image-processing - Krajee Bootstrap 文件输入因大文件而失败
- html - 我在 Chrome 的 FileSystem API 上做错了什么?