繁体   English   中英

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

[英]module.exports class is not found in editor and not a constructor at runtime

我试图要求一个脚本:

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

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

类型“ typeof搜索”上不存在属性“搜索”。

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

TypeError:搜索不是构造函数

型号/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')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM