【问题标题】:Error: Cannot find module 'tslib' on adminbro tutorial错误:在 adminbro 教程中找不到模块“tslib”
【发布时间】:2021-02-19 11:28:38
【问题描述】:

我正在尝试使用管理员兄弟构建一个 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 库应该已经包含这些。

失败的测试环境:

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

谢谢

【问题讨论】:

    标签: node.js tslib admin-bro


    【解决方案1】:

    npm install tslib 解决了我的问题

    【讨论】:

      猜你喜欢
      • 2018-09-05
      • 2019-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      相关资源
      最近更新 更多