【发布时间】:2020-02-13 17:27:54
【问题描述】:
我目前正在尝试将我的 Angular 通用应用程序部署到 Firebase 功能和托管。因此我关注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 有关。只要我在output 内添加library 和libraryTarget,就会出现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)
【问题讨论】:
-
很抱歉我的回答没有奏效。我设法在不使用
library和libraryTarget属性的情况下使其工作(所以只需删除它们)。我更新了答案以反映这一点。您是否也可以尝试删除这些属性并查看它是否有效?明天,我将尝试调查为什么在原始教程中添加了这些属性,以及删除它们是否是正确的选择...... -
感谢您的努力!删除它们确实有效,但会出现另一个错误 - 请参阅编辑!
-
我更新了解决方案,用这种新方法
app-root替换为 HTML(如果不是,则 SSR 不起作用)并且不会出现错误。希望不会有错误,但如果有你可以在这里在 cmets 中回复,我会尝试解决它... :) PS:新方法仅在webpack.server.config.js中有额外的变化。 -
@miselking 谢谢!通过更改外部,我能够添加这两个属性而没有任何错误,并且可以成功部署。不知道为什么,一开始打开网站时,不会出现HTML,而是
app-root。但是,一旦您更改路线并导航到不同的组件,就会出现 HTML 而不是app-root- 怎么会? -
@miselking 换句话说,只有最初的 ' ' 链接/路由不会显示任何内容,对于某些路由,有 HTML 而不是
app-root,对于一个路由,浏览器和 firebase 都超时当我尝试检查源代码时会出现控制台。
标签: angular firebase google-cloud-functions angular-universal