Angular 普遍错误 - app.auth 不是函数
Angular Universal error - app.auth is not a function
技术堆栈: AngularFire2、Firebase、Firebase 函数、Angular 7、
将网站部署到 Firebase Functions 时出现错误,尽管它在本地正常运行。
Angular Cli 和 Angular 通用。
AngularFire2 version: "@angular/fire": "^5.1.2"
Firebase version: "firebase": "^5.9.3"
我已经调试过了,这似乎是 AngularFire2 的问题。
我尝试过的事情:
我已经升级并降级了库,看看是否能修复它,但没有成功。
此外,尝试卸载 npm 包并删除包锁,但也没有成功。
这是 firebase 控制台(函数)上的堆栈跟踪错误:
ERROR TypeError: app.auth is not a function
at /user_code/dist/server.js:152999:24
at ZoneDelegate.invoke (/user_code/dist/server.js:555:26)
at Zone.run (/user_code/dist/server.js:314:43)
at NgZone.runOutsideAngular (/user_code/dist/server.js:20244:28)
at new AngularFireAuth (/user_code/dist/server.js:152997:26)
at _createClass (/user_code/dist/server.js:24259:20)
at _createProviderInstance (/user_code/dist/server.js:24221:26)
at resolveNgModuleDep (/user_code/dist/server.js:24185:21)
at _createClass (/user_code/dist/server.js:24251:29)
at _createProviderInstance (/user_code/dist/server.js:24221:26)
这是我现在的webpack.prerender.config.js:
const path = require('path');
const webpack = require('webpack');
const regex = /firebase\/(app|firestore)/;
module.exports = {
mode: 'none',
entry: {
// This is our Express server for Dynamic universal
server: './server.ts'
},
target: 'node',
resolve: { extensions: ['.ts', '.js'] },
optimization: {
minimize: false
},
output: {
// Puts the output at the root of the dist folder
path: path.join(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'umd',
library: 'app'
},
// this makes sure we include node_modules and other 3rd party libraries
externals: [function(context, request, callback) {
// exclude firebase products from being bundled, so they will be loaded using require() at runtime.
if(regex.test(request)) {
return callback(null, 'commonjs ' + request);
}
callback();
}],
module: {
rules: [
{ test: /\.ts$/, loader: 'ts-loader' },
{
// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
// Removing this will cause deprecation warnings to appear.
test: /(\|\/)@angular(\|\/)core(\|\/).+\.js$/,
parser: { system: true },
},
]
},
plugins: [
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?angular(\|\/)core(.+)?/,
path.join(__dirname, 'src'), // location of your src
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?express(\|\/)(.+)?/,
path.join(__dirname, 'src'),
{}
)
]
};
出现此问题的原因:
"engines": {
"node": "8"
},
函数文件夹中的 package.json 文件中缺少 。
似乎缺少此内容会导致 html 无法使用 ssr 完全呈现。
技术堆栈: AngularFire2、Firebase、Firebase 函数、Angular 7、
将网站部署到 Firebase Functions 时出现错误,尽管它在本地正常运行。
Angular Cli 和 Angular 通用。
AngularFire2 version: "@angular/fire": "^5.1.2"
Firebase version: "firebase": "^5.9.3"
我已经调试过了,这似乎是 AngularFire2 的问题。
我尝试过的事情:
我已经升级并降级了库,看看是否能修复它,但没有成功。
此外,尝试卸载 npm 包并删除包锁,但也没有成功。
这是 firebase 控制台(函数)上的堆栈跟踪错误:
ERROR TypeError: app.auth is not a function
at /user_code/dist/server.js:152999:24
at ZoneDelegate.invoke (/user_code/dist/server.js:555:26)
at Zone.run (/user_code/dist/server.js:314:43)
at NgZone.runOutsideAngular (/user_code/dist/server.js:20244:28)
at new AngularFireAuth (/user_code/dist/server.js:152997:26)
at _createClass (/user_code/dist/server.js:24259:20)
at _createProviderInstance (/user_code/dist/server.js:24221:26)
at resolveNgModuleDep (/user_code/dist/server.js:24185:21)
at _createClass (/user_code/dist/server.js:24251:29)
at _createProviderInstance (/user_code/dist/server.js:24221:26)
这是我现在的webpack.prerender.config.js:
const path = require('path');
const webpack = require('webpack');
const regex = /firebase\/(app|firestore)/;
module.exports = {
mode: 'none',
entry: {
// This is our Express server for Dynamic universal
server: './server.ts'
},
target: 'node',
resolve: { extensions: ['.ts', '.js'] },
optimization: {
minimize: false
},
output: {
// Puts the output at the root of the dist folder
path: path.join(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'umd',
library: 'app'
},
// this makes sure we include node_modules and other 3rd party libraries
externals: [function(context, request, callback) {
// exclude firebase products from being bundled, so they will be loaded using require() at runtime.
if(regex.test(request)) {
return callback(null, 'commonjs ' + request);
}
callback();
}],
module: {
rules: [
{ test: /\.ts$/, loader: 'ts-loader' },
{
// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
// Removing this will cause deprecation warnings to appear.
test: /(\|\/)@angular(\|\/)core(\|\/).+\.js$/,
parser: { system: true },
},
]
},
plugins: [
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?angular(\|\/)core(.+)?/,
path.join(__dirname, 'src'), // location of your src
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?express(\|\/)(.+)?/,
path.join(__dirname, 'src'),
{}
)
]
};
出现此问题的原因:
"engines": { "node": "8" },
函数文件夹中的 package.json 文件中缺少。 似乎缺少此内容会导致 html 无法使用 ssr 完全呈现。