1

我正在尝试使用管理员兄弟构建一个 nodejs 应用程序。

他们在此处提供了基于角色的访问示例的教程

我运行这些来为应用程序创建一个新目录:

mkdir my-admin-app
cd my-admin-app
yarn init -y

要安装依赖项,我运行:

yarn add express express-formidable mongoose admin-bro @admin-bro/mongoose @admin-bro/express

这是示例应用程序...

// Requirements
const mongoose = require('mongoose')
const express = require('express')
const AdminBro = require('admin-bro')
const AdminBroExpressjs = require('@admin-bro/express')

// We have to tell AdminBro that we will manage mongoose resources with it
AdminBro.registerAdapter(require('@admin-bro/mongoose'))

// express server definition
const app = express()

// Resources definitions
const User = mongoose.model('User', {
  email: { type: String, required: true },
  password: { type: String, required: true },
  role: { type: String, enum: ['admin', 'restricted'], required: true },
})

// Pass all configuration settings to AdminBro
const adminBro = new AdminBro({
  resources: [User],
  rootPath: '/admin',
})

// Build and use a router which will handle all AdminBro routes
const router = AdminBroExpressjs.buildRouter(adminBro)
app.use(adminBro.options.rootPath, router)

// Running the server
const run = async () => {
  await mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true })
  await app.listen(8080, () => console.log(`Example app listening on port 8080!`))
}

run()

测试一切都按预期工作......

node index.js

预期的输出是这样的:

AdminBro: bundle ready
Example app listening on port 8080!

但我明白了:

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'tslib'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)

我遇到了这个问题,但是示例应用程序中没有使用建议的导入,所以我认为 adminbro 库已经应该包含这些。

失败的测试环境:

  • 带有 yarn 和 npm 的本地 Nodejs 版本 10
  • docker 上的新 Nodejs 版本 15(全新容器)

谢谢

4

1 回答 1

1

npm install tslib解决了我的问题

于 2021-02-28T11:57:57.913 回答