简体   繁体   English

未捕获的类型错误:_models_Search__WEBPACK_IMPORTED_MODULE_0___default.a 不是构造函数

[英]Uncaught TypeError: _models_Search__WEBPACK_IMPORTED_MODULE_0___default.a is not a constructor

I am following a tutorial on Javascript- currently building a app which involves uses classes I have encountered an error which is the title of this question 'Uncaught TypeError: _models_Search__WEBPACK_IMPORTED_MODULE_0___default.a is not a constructor' this project involves using the MVC design pattern also.我正在关注关于 Javascript 的教程 - 目前正在构建一个涉及使用类的应用程序我遇到了一个错误,它是这个问题的标题“未捕获的 TypeError:_models_Search__WEBPACK_IMPORTED_MODULE_0___default.a 不是构造函数”这个项目也涉及使用 MVC 设计模式。

I have tried to rename import Search from './models/Search';我试图从'./models/Search'重命名导入搜索; to import {Search} from './models/Search';从'./models/Search'导入{Search}; but still I am being greeted with this full error message:但我仍然收到这个完整的错误消息:

Uncaught TypeError: _models_Search__WEBPACK_IMPORTED_MODULE_0___default.a is not a constructor
    at eval (index.js:5)
    at Module../src/js/index.js (bundle.js:4198)
    at __webpack_require__ (bundle.js:20)
    at eval (webpack:///multi_(:8080/webpack)-dev-server/client?:3:18)
    at Object.0 (bundle.js:4220)
    at __webpack_require__ (bundle.js:20)
    at bundle.js:84
    at bundle.js:87

Search.js file搜索.js 文件

      import axios from 'axios';

      export default class Search {
      constructor(query) {
        this.query = query;
      }

      async getResults() {
        const proxy = 'https://cors-anywhere.herokuapp.com/'; const 
      key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
        try {
            const res = await 
      axios(`${proxy}https://www.food2fork.com/api/search? 
      key=${key}&q=${this.query}`);
            this.result = res.data.recipes;
            console.log(recipes);
         } catch (error) {
            alert(error);
         }

      }
       }

index.js file index.js 文件

      import Search from './models/Search';

      const search = new Search('pizza');
      console.log(search);

the expected outcome is for the the search property to be returned in the client and for me to be able to access all of its properties within the browser.预期的结果是在客户端中返回搜索属性,并且我能够在浏览器中访问其所有属性。 and yes I have purposely x'd out the API key just in case you were wondering- would actually help too if the answer is given you can give me a brief breakdown as to where I went wrong.是的,我特意删除了 API 密钥,以防万一您想知道-如果给出答案,实际上也会有所帮助,您可以简要介绍一下我哪里出错了。 Thanks in advance.提前致谢。

To correctly import your Search class use the following lines of code.要正确导入您的搜索 class,请使用以下代码行。 In index.js:在 index.js 中:

import Search from './models/Search';

And in Search class declaration:并在搜索 class 声明:

export default class Search

Or second way that you tried (with braces in import): in index.js或者您尝试的第二种方式(在导入中使用大括号):在 index.js 中

import { Search } from './models/Search';

And export, without default :并导出,没有默认值

export class Search

Braces needed only in named exports仅在命名导出中需要大括号

暂无
暂无

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

相关问题 未捕获的类型错误:__WEBPACK_IMPORTED_MODULE_7__vanilla_tabs__ 不是构造函数 - Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_7__vanilla_tabs__ is not a constructor 类型错误:_models_Products__WEBPACK_IMPORTED_MODULE_1__.default.find 不是函数 - TypeError: _models_Products__WEBPACK_IMPORTED_MODULE_1__.default.find is not a function 未捕获的类型错误:__WEBPACK_IMPORTED_MODULE_0_react___default.a.createContext 不是 function - Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_react___default.a.createContext is not a function 未捕获的类型错误:_firebase__WEBPACK_IMPORTED_MODULE_3__.default.collections 不是 function - Uncaught TypeError: _firebase__WEBPACK_IMPORTED_MODULE_3__.default.collections is not a function WebpackError: TypeError: p5__WEBPACK_IMPORTED_MODULE_4___default.a 不是构造函数 - WebpackError: TypeError: p5__WEBPACK_IMPORTED_MODULE_4___default.a is not a constructor “TypeError:chart_js__WEBPACK_IMPORTED_MODULE_9__.default 不是构造函数” - "TypeError: chart_js__WEBPACK_IMPORTED_MODULE_9__.default is not a constructor" webpack 导入模块未找到错误:未捕获类型错误:_useFetch__WEBPACK_IMPORTED_MODULE_0__["default"](...) 为 null - webpack import module not found error: Uncaught TypeError: _useFetch__WEBPACK_IMPORTED_MODULE_0__["default"](...) is null 如何修复TypeError:application_module__WEBPACK_IMPORTED_MODULE_1 ___ default.a不是构造函数 - How to fix TypeError: application_module__WEBPACK_IMPORTED_MODULE_1___default.a is not a constructor Uncaught TypeError: WEBPACK_IMPORTED_MODULE_1__.default is undefined (React, SASS,SCSS) - Uncaught TypeError: WEBPACK_IMPORTED_MODULE_1__.default is undefined (React, SASS,SCSS) 我一直遇到这个错误: Uncaught TypeError: firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.auth is not a function - I keep running into this error: Uncaught TypeError: firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.auth is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM