【发布时间】:2019-01-12 19:42:07
【问题描述】:
我正在构建 Angular 7 应用程序并使用 Angular Universal 进行服务器端渲染,在本地一切正常,但是当我尝试在 Firebase 上部署应用程序时,Firebase 函数日志显示以下错误 -
{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Build failed: exit status 254\nnpm ERR! addLocal Could not install /workspace/node_modules/@ng-toolkit/universal/@ng-toolkit/_utils@1.1.50\nnpm WARN deprecated bugsnag@2.4.3: All projects should upgrade to our universal JS notifier: \"@bugsnag/js\". See https://github.com/bugsnag/bugsnag-js/blob/master/UPGRADING.md for more details.\nnpm ERR! Linux 4.15.0-1026-gcp\nnpm ERR! argv \"/nodejs/bin/node\" \"/nodejs/bin/npm\" \"--global-style\" \"--production\" \"--fetch-retries=5\" \"--fetch-retry-factor=2\" \"--fetch-retry-mintimeout=1000\" \"install\" \"/workspace\"\nnpm ERR! node v6.14.0\nnpm ERR! npm v3.10.10\nnpm ERR! path /workspace/node_modules/@ng-toolkit/universal/@ng-toolkit/_utils@1.1.50\nnpm ERR! code ENOENT\nnpm ERR! errno -2\nnpm ERR! syscall open\n\nnpm ERR! enoent ENOENT: no such file or directory, open '/workspace/node_modules/@ng-toolkit/universal/@ng-toolkit/_utils@1.1.50'\nnpm ERR! enoent ENOENT: no such file or directory, open '/workspace/node_modules/@ng-toolkit/universal/@ng-toolkit/_utils@1.1.50'\nnpm ERR! enoent This is most likely not a problem with npm itself\nnpm ERR! enoent and is related to npm not being able to find a file.\nnpm ERR! enoent \n\nnpm ERR! Please include the following file with any support request:\nnpm ERR! /workspace/npm-debug.log\n"},"authenticationInfo":.....
functions/package.json 中的设置
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"@angular/animations": "~7.0.0",
"@angular/common": "~7.0.0",
"@angular/compiler": "~7.0.0",
"@angular/core": "~7.0.0",
"@angular/fire": "^5.1.1",
"@angular/forms": "~7.0.0",
"@angular/http": "~7.0.0",
"@angular/platform-browser": "~7.0.0",
"@angular/platform-browser-dynamic": "~7.0.0",
"@angular/platform-server": "~7.0.0",
"@angular/router": "~7.0.0",
"@ng-toolkit/universal": "^1.1.50",
"@nguniversal/express-engine": "~7.0.0",
"@nguniversal/module-map-ngfactory-loader": "~7.0.0",
"bootstrap": "^4.1.3",
"bootswatch": "^4.1.3",
"core-js": "^2.5.4",
"cors": "~2.8.4",
"firebase": "^5.7.2",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"rxjs": "~6.3.3",
"ts-loader": "4.2.0",
"webpack-cli": "^3.1.2",
"zone.js": "~0.8.26",
"@nguniversal/common": "~7.0.0",
"express": "~4.16.3",
"firebase-admin": "~6.0.0",
"firebase-functions": "^2.1.0"
},
"private": true
}
我该如何解决这个错误?
【问题讨论】:
-
请注意:无服务器函数目前有一个“冷启动”时间,可以是几秒钟。因此,恕我直言,如果目标是性能,那么无服务器不是 Angular Universal 的最佳解决方案。准备好加载时间为 600 毫秒,而“冷”启动的情况会更糟。
-
@CanK。 - 是的,我同意你的看法,老实说,我不这么认为,请对此提出一些建议。我可以使用什么,不可以使用什么?我主要将 Universal 用于 SEO,而不是性能,因为它有助于生成搜索引擎可以看到的内容。
-
如果您的网站不是动态的,您可以使用通用预渲染它,例如每 24 小时或每月一次,并将 HTML 作为静态文件提供。或者你使用无服务器并添加类似 CloudFlare 的东西。那也会很快。一般来说,我们有多个使用 Angular 运行的站点,有些使用 Universal,有些没有。谷歌可以毫无问题地渲染所有这些。只有其他搜索引擎有问题。最简单和最好的结果可能是使用 Serverless 和 CDN,如 CloudFlare infront。您将体验到完美的性能,并且该网站已预渲染。
-
感谢您的建议,我的网站不是动态的,因此我认为我现在应该选择静态的。
标签: angular firebase angular-universal