【问题标题】:TypeError: Cannot read property 'prototype' of undefinedTypeError:无法读取未定义的属性“原型”
【发布时间】:2021-08-01 22:34:12
【问题描述】:

节点版本:6.14.11, 操作系统

我希望能够像这样使用 'response from express' 和 'json from body-parser'.. 尽管如此,vscode 并没有打开我写的“导入代码”

我说的首先是我认为的问题。但我不能确定:(

enter image description here

import Axios from 'axios';
import { json } from 'body-parser';
import { response } from 'express';
import {React, useEffect} from 'react'
// import { FaCode } from "react-icons/fa";
import {API_URL, API_KEY} from '../../Config';

function LandingPage() {

    useEffect(()=>{
        const endpoint = `${API_URL}movie/popular?api_key=${API_KEY}&language=en-US&page=1`;

        fetch(endpoint)
        .then(response => response.json())
        .then(response => console.log(response));


        // Axios.get(endpoint) 
        // .then(response => {
        //     setMovies([...response.results])
        //     setMainMoveImage(response.results[0])
        // })
        // endpoint에 받은 값(API)을 fetch가 가져온다? 그렇게보면 될듯
        // 그 값이 response에 담긴다.  하지만 response만으로 response을 읽을 수 없기에
        // json()을 사용해줌.
    },[])


    return (
        <>
            <div style={{ width: '100%', margin: '0'}}>

                {/* Main Image */}

                <div style={{ width: '85%', margin: '1rem auto'}}>

                    <h2>Movies by latest</h2>
                    <hr />

                    {/* Movie Grid Cards */}


                </div>

                <div style={{ display: 'flex', justifyContent: 'center'}}>
                    <button>Load More</button>
                </div>

            </div>
        </>
    )
}

export default LandingPage

【问题讨论】:

  • 这将有助于获取错误堆栈(文件名和行号)

标签: node.js json reactjs


【解决方案1】:

我遇到了这个问题! 我知道vscode会自动导入代码!

如果我这样删除,那就太好了

// This is what i will delete!
import { json } from 'body-parser';
import { response } from 'express';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-05
    • 2020-05-11
    • 2021-10-31
    • 2020-05-15
    • 2019-09-24
    • 2021-11-20
    相关资源
    最近更新 更多