类型错误:无法读取未定义的属性“原型”为什么运行 Browserify 后会出现此错误?

问题描述

我已经安装并完成了 browserify 的整个设置。我把我的 main.js 打包成 bundle.js

但是现在在我节点运行 bundle.js 之后。它给了我一个错误,如:

TypeError: 无法读取未定义的属性 'prototype'

给我错误的那一行是这样的:

var res = Object.create(http.ServerResponse.prototype);

这是我的 main.js:

var unique = require('uniq');
const express = require('express');
const app = express();
const fetch = require('node-fetch');

var data = [ 1,2,3,4,5,6 ];

console.log(unique(data));

app.use(express.static('public'));

app.get('/',async (req,res) => {
    let access_token;
    let token_type;
    if (req.query.code) {
        const accessCode = req.query.code;
        const data = {
            client_id     : '',client_secret : '',grant_type    : 'authorization_code',redirect_uri  : 'http://localhost:3000',code          : accessCode,scope         : 'identify'
        };

        const res = await fetch('https://discordapp.com/apI/Oauth2/token',{
            method  : 'POST',body    : new URLSearchParams(data),headers : {
                'Content-Type' : 'application/x-www-form-urlencoded'
            }
        });

        const info = await res.json();

        token_type = info.token_type;
        access_token = info.access_token;

        const post = await fetch('https://discordapp.com/api/users/@me',{
            headers : {
                authorization : `${token_type} ${access_token}`
            }
        });
    }

    if (token_type && access_token && req.query.state) {
        res
            .status(200)
            .redirect(
                `http://localhost:3000/?code=${req.query.code}&state=${req.query
                    .state}&access_token=${access_token}&token_type=${token_type}`
            );
    } else {
        res.sendFile('index.html',{ root: '.' });
    }
});

app.listen(3000);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)