错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:没有“出口” - Firebase
Posted
技术标签:
【中文标题】错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:没有“出口” - Firebase【英文标题】:Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" - Firebase 【发布时间】:2021-11-10 23:28:42 【问题描述】:通过此Full Stack React & Firebase Tutorial 并尝试使用 Firebase 身份验证来创建新用户,我收到以下错误。
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /socialapp-functions/functions/node_modules/firebase/package.json
at throwExportsNotFound (internal/modules/esm/resolve.js:299:9)
at packageExportsResolve (internal/modules/esm/resolve.js:522:3)
at resolveExports (internal/modules/cjs/loader.js:449:36)
at Function.Module._findPath (internal/modules/cjs/loader.js:489:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:875:27)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/socialapp-functions/functions/index.js:17:18)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
⚠ We were unable to load your functions code. (see above)
教程详细代码如下:
// Signup route
app.post("/signup", (req, res) =>
const newUser =
email: req.body.email,
password: req.body.password,
confirmPassword: req.body.confirmPassword,
handle: req.body.handle,
;
firebase
.auth()
.createUserWithEmailAndPassword(newUser.email, newUser.password)
.then((data) =>
return res
.status(201)
.json( message: `user $data.user.uid signed up successfully` );
)
.catch((err) =>
console.error(err);
return res.status(500).json( error: err.code );
);
);
【问题讨论】:
【参考方案1】:根据here 的问答,我认为问题在于当我运行 Firebase@9 时,本教程包含 Firebase@8 的代码。
将 Firebase Admin SDK 文档引用到 Manage Users,我正在使用
const admin = require("firebase-admin");
而不是
const firebase = require("firebase");
我将代码更新为以下内容,现在可以在 POST 上成功添加用户。
// Signup route
app.post("/signup", (req, res) =>
const newUser =
email: req.body.email,
password: req.body.password,
confirmPassword: req.body.confirmPassword,
handle: req.body.handle,
phone: req.body.phone,
name: req.body.name,
photoURL: req.body.photo,
;
admin
.auth()
.createUser(
email: newUser.email,
emailVerified: false,
phoneNumber: newUser.phone,
password: newUser.password,
displayName: newUser.name,
photoURL: newUser.photoURL,
disabled: false,
)
.then((data) =>
return res
.status(201)
.json( message: `user $data.uid signed up successfully` );
)
.catch((err) =>
console.error(err);
return res.status(500).json( error: err.code );
);
);
【讨论】:
【参考方案2】:有了这些版本,它就可以工作了!!降级/升级这些依赖项以匹配
"dependencies":
"firebase": "^8.10.0",
"firebase-admin": "^8.13.0",
"firebase-functions": "^3.14.1"
,
【讨论】:
我不知道为什么,但它有效。 @ViacheslavDobromyslov 它可以工作,因为建议的答案是使用较旧的 Firebase SDK以上是关于错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:没有“出口” - Firebase的主要内容,如果未能解决你的问题,请参考以下文章
Python学习笔记__8章错误调试和测试__8.1章错误处理
__x__(72)1011第十二天__ JavaScript 错误处理机制