gpt4 book ai didi

javascript - 引用错误 : process is not defined Module. ../../../node_modules/graphql/jsutils/instanceOf.mjs

转载 作者:行者123 更新时间:2023-12-04 03:36:10 27 4
gpt4 key购买 nike

我正在为我的项目使用 graphql 订阅,它是一个 instagram 克隆,我正在执行喜欢或不喜欢帖子的功能,我使用 npx create-react-app创建我的客户,我使用 express做我的服务器。
在客户端,我设置了我的 client像那样:src/apis/client.js

import {
ApolloClient,
ApolloLink,
HttpLink,
InMemoryCache,
split,
} from 'apollo-boost';
import {getMainDefinition} from '@apollo/client/utilities';
import {WebSocketLink} from '@apollo/client/link/ws';
const httpUrl = 'http://localhost:5000/graphql';
const wsUrl = 'ws://localhost:5000/graphql';

const httpLink = ApolloLink.from([
new ApolloLink((operation, forward) => {}),
new HttpLink({uri: httpUrl}),
]);

const wsLink = new WebSocketLink({
uri: wsUrl,
options: {
// connectionParams: () => {},
lazy: true,
reconnect: true,
},
});

function isSubscription(operation) {
const definition = getMainDefinition(operation.query);
return (
definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
);
}

const client = new ApolloClient({
cache: new InMemoryCache(),
link: split(isSubscription, wsLink, httpLink),
defaultOptions: {query: {fetchPolicy: 'no-cache'}},
});

export default client;
如您所见,我同时使用 websocket 和 https 连接。以前,我只使用 http 连接,一切正常。
这是我的 server边: app.js
const {ApolloServer, gql} = require('apollo-server-express');
const http = require('http');
const fs = require('fs');
const bodyParser = require('body-parser');
const cors = require('cors');
const express = require('express');

const app = express();
app.use(cors(), bodyParser.json());

const typeDefs = gql(fs.readFileSync('./schema.graphql', {encoding: 'utf8'}));

const resolvers = require('./resolvers');

const apolloServer = new ApolloServer({
typeDefs,
resolvers,
});
apolloServer.applyMiddleware({app, path: '/graphql'});

const httpServer = http.createServer(app);
apolloServer.installSubscriptionHandlers(httpServer);
const port = 5000;
httpServer.listen(port, () => console.log(`Server started on port ${port}`));
这是错误:
enter image description here
我试图用谷歌搜索,但看起来 React 的 webpack.config 文件中缺少某些东西,但我不知道 webpack。请告诉我如何处理它,非常感谢,祝你有美好的一天

最佳答案

安装特定软件包的最新版本后,我遇到了同样的问题。能够通过删除 node_modules 解决问题和 package-lock.json和正在运行的 npm install再次。

关于javascript - 引用错误 : process is not defined Module. ../../../node_modules/graphql/jsutils/instanceOf.mjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66869388/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com