[英]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.