将Angular Universal应用程序部署到Firebase Functions会返回错误

时间:2019-10-16 21:01:48

标签: angular firebase google-cloud-functions angular-universal

我目前正在尝试将Angular Universal App部署到Firebase Functions&Hosting。因此,我正在关注this tutorial

Error: Error parsing triggers: Cannot find module 'require("./server/main")'

Require stack:
- /Users/timfuhrmann/Documents/Entwicklung/norebro/functions/dist/server.js
- /Users/timfuhrmann/Documents/Entwicklung/norebro/functions/lib/index.js
- /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js

我认为这与webpack.server.config.js有关。我在library内添加libraryTargetoutput时,对于firebase deploy npm run serve:ssr出现错误:

...
output: {
    // Puts the output at the root of the dist folder
    path: path.join(__dirname, 'dist'),
    library: 'app',
    libraryTarget: 'umd',
    filename: '[name].js'
},
...


完整的日志:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'serve:ssr' ]
2 info using npm@6.12.0
3 info using node@v12.6.0
4 verbose run-script [ 'preserve:ssr', 'serve:ssr', 'postserve:ssr' ]
5 info lifecycle norebro@0.0.0~preserve:ssr: norebro@0.0.0
6 info lifecycle norebro@0.0.0~serve:ssr: norebro@0.0.0
7 verbose lifecycle norebro@0.0.0~serve:ssr: unsafe-perm in lifecycle true
8 verbose lifecycle norebro@0.0.0~serve:ssr: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/timfuhrmann/Documents/Entwicklung/norebro/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Apple/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/timfuhrmann/Documents/Entwicklung/norebro/node_modules/.bin
9 verbose lifecycle norebro@0.0.0~serve:ssr: CWD: /Users/timfuhrmann/Documents/Entwicklung/norebro
10 silly lifecycle norebro@0.0.0~serve:ssr: Args: [ '-c', 'node dist/server' ]
11 silly lifecycle norebro@0.0.0~serve:ssr: Returned: code: 1  signal: null
12 info lifecycle norebro@0.0.0~serve:ssr: Failed to exec serve:ssr script
13 verbose stack Error: norebro@0.0.0 serve:ssr: `node dist/server`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:203:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:203:13)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid norebro@0.0.0
15 verbose cwd /Users/timfuhrmann/Documents/Entwicklung/norebro
16 verbose Darwin 19.0.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "serve:ssr"
18 verbose node v12.6.0
19 verbose npm  v6.12.0
20 error code ELIFECYCLE
21 error errno 1
22 error norebro@0.0.0 serve:ssr: `node dist/server`
22 error Exit status 1
23 error Failed at the norebro@0.0.0 serve:ssr script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]


编辑
首先,当您打开网站时,将没有HTML而不是app-root。一旦更改路线并导航到其他组件,就会有HTML而不是app-root-怎么了?

Firebase Functions控制台有时返回成功执行,有时返回某些@type信息,甚至有时返回错误:

TypeError: handler is not a function
    at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:49:9)
    at /worker/worker.js:783:7
    at /worker/worker.js:766:11
    at ZoneDelegate.invokeTask (/srv/dist/server.js:575:31)
    at Zone.runTask (/srv/dist/server.js:347:47)
    at ZoneTask.invokeTask (/srv/dist/server.js:650:34)
    at ZoneTask.invoke (/srv/dist/server.js:639:48)
    at data.args.(anonymous function) (/srv/dist/server.js:1619:25)
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)

1 个答案:

答案 0 :(得分:0)

对于Future错误,只需在server.ts文件中将TypeError: handler is not a function替换为const app = express();

来源:https://stackoverflow.com/a/58447459/12595124