module.exports 类在编辑器中找不到,在运行时也找不到构造函数



我正在尝试需要一个脚本:

const { Search } = require('../models/Search')

作为回报,我在编辑器中给了我这个错误:

属性"搜索"在

类型"搜索"上不存在。

当我执行代码时,我在控制台中收到此错误:

类型错误:搜索不是构造函数

型号/搜索.js

module.exports = class Search extends Model { 
  constructor() {
    super()
    // Set some property values here
  }
}

我在这里错过了什么?

模块导出是类本身Search,而不是将其作为Search属性包含的对象。

它应该是:

module.exports = class Search extends Model {...}

const Search = require('../models/Search')

或:

exports.Search = class Search extends Model {...}

const { Search } = require('../models/Search')

最新更新