我正在尝试构建一个使用管理兄弟的nodejs应用程序。
他们为基于角色的访问示例Here提供了一个教程。
我运行这些程序来为应用程序创建一个新目录:
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)我偶然看到了这个question,但是导入表明示例应用程序中没有使用它,所以我认为adminbro应该已经包含了这些。
测试失败的环境:
上
谢谢
发布于 2021-02-28 11:57:57
npm install tslib在我的案件中解决了这个问题
https://stackoverflow.com/questions/66276733
复制相似问题