将Angular Universal应用部署到Firebase函数会返回错误

问题描述 投票:0回答:1

我目前正在尝试将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 [email protected]
3 info using [email protected]
4 verbose run-script [ 'preserve:ssr', 'serve:ssr', 'postserve:ssr' ]
5 info lifecycle [email protected]~preserve:ssr: [email protected]
6 info lifecycle [email protected]~serve:ssr: [email protected]
7 verbose lifecycle [email protected]~serve:ssr: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~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 [email protected]~serve:ssr: CWD: /Users/timfuhrmann/Documents/Entwicklung/norebro
10 silly lifecycle [email protected]~serve:ssr: Args: [ '-c', 'node dist/server' ]
11 silly lifecycle [email protected]~serve:ssr: Returned: code: 1  signal: null
12 info lifecycle [email protected]~serve:ssr: Failed to exec serve:ssr script
13 verbose stack Error: [email protected] 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 [email protected]
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 [email protected] serve:ssr: `node dist/server`
22 error Exit status 1
23 error Failed at the [email protected] 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)
angular firebase google-cloud-functions angular-universal
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.