Getting error on my express project: TypeError: Cannot read properties of undefined (reading 'prototype')
Getting error on my express project: TypeError: Cannot read properties of undefined (reading 'prototype')
出于某种原因,我的 javascript 文件中出现了 TypeError: Cannot read properties of undefined (reading 'prototype')
。从我在网上看到的情况来看,人们似乎发现从 express 导入 {response} 是罪魁祸首,但我没有这样做。
import { Button } from '../Button';
import "./index.css";
import {clientId,clientSecret} from "./config.json"
import passport from "passport";
const express = require('express');
const app = express();
var DiscordStrategy = require('passport-discord').Strategy;
export const OAuth = (): JSX.Element => {
var scopes = ['identify', 'guilds', 'guilds.members.read'];
passport.use(new DiscordStrategy({
clientID: clientId,
clientSecret: clientSecret,
callbackURL: 'http://localhost:3000',
scope: scopes
}))
app.get('/auth/discord', passport.authenticate('discord'));
app.get('/auth/discord/callback', passport.authenticate('discord', {
failureRedirect: '/'
}), function(req:any, res:any) {
console.log(res)
res.redirect('http://localhost:3000') // Successful auth
});
async function openLink(url:any) {
window.open(url)
}
return (
<div>
<Button onClick={async() => await openLink("link goes here")} className="discordconnect">
Connect Discord
</Button>
</div>
);
}
export default OAuth;
TypeError: Cannot read properties of undefined (reading 'prototype')
当您尝试在浏览器环境中 运行 表达时,似乎会发生此错误。
(见code sandbox with the same error)
Express 是一个网络服务器。它 运行 在 node.js 上运行,通常从计算机上的终端提示符启动。它提供对从浏览器发送的 http 请求的响应。
React 是浏览器中 运行 的前端 UI 框架。它根据加载的数据和用户与该页面的交互操作页面上显示的 HTML 内容。
您似乎正试图从浏览器中的 React 组件 运行ning 启动一个快速应用程序。 Express 不支持此功能。 express 在浏览器中不能是运行。事实上,由于浏览器安全策略,无法从 Web 浏览器托管任何服务器。
我不知道你想做什么,但你需要从根本上重新考虑你的方法。
通常,当你开始开发这个时,你会创建一个带有 express 的服务器,为 一个 React 应用程序提供服务。您从计算机的命令行终端启动服务器,然后导航到该服务器提供的 URL,它会在您的浏览器中加载您的 React 应用程序。
你永远不会从 React 组件创建服务器,因为那是不可能的,也没有多大意义。
出于某种原因,我的 javascript 文件中出现了 TypeError: Cannot read properties of undefined (reading 'prototype')
。从我在网上看到的情况来看,人们似乎发现从 express 导入 {response} 是罪魁祸首,但我没有这样做。
import { Button } from '../Button';
import "./index.css";
import {clientId,clientSecret} from "./config.json"
import passport from "passport";
const express = require('express');
const app = express();
var DiscordStrategy = require('passport-discord').Strategy;
export const OAuth = (): JSX.Element => {
var scopes = ['identify', 'guilds', 'guilds.members.read'];
passport.use(new DiscordStrategy({
clientID: clientId,
clientSecret: clientSecret,
callbackURL: 'http://localhost:3000',
scope: scopes
}))
app.get('/auth/discord', passport.authenticate('discord'));
app.get('/auth/discord/callback', passport.authenticate('discord', {
failureRedirect: '/'
}), function(req:any, res:any) {
console.log(res)
res.redirect('http://localhost:3000') // Successful auth
});
async function openLink(url:any) {
window.open(url)
}
return (
<div>
<Button onClick={async() => await openLink("link goes here")} className="discordconnect">
Connect Discord
</Button>
</div>
);
}
export default OAuth;
TypeError: Cannot read properties of undefined (reading 'prototype')
当您尝试在浏览器环境中 运行 表达时,似乎会发生此错误。
(见code sandbox with the same error)
Express 是一个网络服务器。它 运行 在 node.js 上运行,通常从计算机上的终端提示符启动。它提供对从浏览器发送的 http 请求的响应。
React 是浏览器中 运行 的前端 UI 框架。它根据加载的数据和用户与该页面的交互操作页面上显示的 HTML 内容。
您似乎正试图从浏览器中的 React 组件 运行ning 启动一个快速应用程序。 Express 不支持此功能。 express 在浏览器中不能是运行。事实上,由于浏览器安全策略,无法从 Web 浏览器托管任何服务器。
我不知道你想做什么,但你需要从根本上重新考虑你的方法。
通常,当你开始开发这个时,你会创建一个带有 express 的服务器,为 一个 React 应用程序提供服务。您从计算机的命令行终端启动服务器,然后导航到该服务器提供的 URL,它会在您的浏览器中加载您的 React 应用程序。
你永远不会从 React 组件创建服务器,因为那是不可能的,也没有多大意义。