提问人:MahaElrays 提问时间:11/16/2023 更新时间:11/16/2023 访问量:19
模块构建失败:UnhandledSchemeError:插件无法处理从“node:http”读取
Module build failed: UnhandledSchemeError: Reading from "node:http" is not handled by plugins
问:
我尝试这样做,我正在编译 webpack 时出现 10 个错误和 1 个警告,该问题显示在节点缓冲区中。我更新了节点版本和 npm,但仍然显示相同的错误。 我使用 fetch 从 auth0 获取访问令牌。
import React, { useState } from 'react';
import fetch from 'node-fetch';
const RegistrationForm = () => {
const handleSubmit = async (e) => {
e.preventDefault();
if (formData.authMethod === 'UserIDPassword') {
try {
const invitationResponse = await sendInvitation(formData.whitelistedDomains);
console.log('Invitation sent:', invitationResponse);
} catch (error) {
console.error('Error sending invitation:', error);
}
} else {
console.log(' Handle form submission for other authentication methods');
}
};
const sendInvitation = async (domains) => {
const domainArray = domains.split(',').map((domain) => domain.trim());
try {
const options = {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: `{
"client_id":"${process.env.REACT_APP_AUTH0_MANAGEMENT_CLIENT_ID}",
"client_secret":"${process.env.REACT_APP_AUTH0_MANAGEMENT_CLIENT_SECRET}",
"audience":"${process.env.REACT_APP_AUTH0_API_Audience}",
"grant_type":"client_credentials"}`
};
const response = await fetch(`https://${process.env.REACT_APP_AUTH0_MANAGEMENT_DOMAIN}/oauth/token`,options);
const data = await response.json();
const tokenResponse = data.access_token;
const YOUR_AUTH0_DOMAIN = process.env.REACT_APP_AUTH0_MANAGEMENT_DOMAIN;
const managementApiUrl = `https://${YOUR_AUTH0_DOMAIN}/api/v2`;
const createUserUrl = `${managementApiUrl}/users`;
const createInviteUrl = `${managementApiUrl}/invitations`;
const userResponse = await fetch(createUserUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${tokenResponse}`,
},
body: JSON.stringify({
email: formData.email,
username: formData.username,
}),
});
const user = await userResponse.json();
const inviteResponse = await fetch(createInviteUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${tokenResponse}`,
},
body: JSON.stringify({
user_id: user.user_id,
inviter_id: 'YOUR_USER_ID',
invitee_email: formData.email,
invited_domains: domainArray,
}),
});
const invitation = await inviteResponse.json();
return invitation;
} catch (error) {
console.error('Error sending invitation:', error);
throw error;
}
};
};
export default RegistrationForm;
答: 暂无答案
评论