【问题标题】:uncaught promise rejection: failed to eval source for module 'nanoid': node_modules/nanoid/index.cjs未捕获的承诺拒绝:无法评估模块“nanoid”的源:node_modules/nanoid/index.cjs
【发布时间】:2021-02-16 13:32:13
【问题描述】:

我正在尝试使用 nanoid (https://www.npmjs.com/package/nanoid/v/2.1.2)

exports = async function(){
  const nanoid = require("nanoid");
  const uid = nanoid(10);
}

从 MongoDB 领域运行时中,但它抛出:

uncaught promise rejection: failed to eval source for module 'nanoid': node_modules/nanoid/index.cjs: Line 9:7 Unexpected identifier (and 16 more errors)

这就是我可以从 Realm Dashboard 中看到的所有错误。

可能缺少什么?

【问题讨论】:

  • 必须将 const nanoid = require("nanoid") 从函数中取出,使用 asinc/await 语法,返回promise。

标签: javascript node.js mongodb mongodb-realm


【解决方案1】:

对我有用的解决方案:

  • 安装较低版本的 nanoid
npm i nanoid@2.1.2

然后通过仪表板将包上传到 MongoDB Realm 函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-06
    • 2021-01-26
    • 2015-10-06
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 2022-07-22
    相关资源
    最近更新 更多