未捕获的承诺拒绝:无法评估模块 'nanoid' 的源代码:node_modules/nanoid/index.cjs

uncaught promise rejection: failed to eval source for module 'nanoid': node_modules/nanoid/index.cjs

我正在尝试使用纳米机器人 (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 仪表板中看到的所有错误。

可能缺少什么?

对我有用的解决方案:

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

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