簡體   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