gpt4 book ai didi

node.js - ApolloClient 不是构造函数(带有 nodejs 的 apollo-client)

转载 作者:搜寻专家 更新时间:2023-10-31 23:32:09 25 4
gpt4 key购买 nike

我没有任何 UI 框架。只是一个简单的 Nodejs 脚本,我需要在其中查询 GraphQL。

代码:

const ApolloClient = require('apollo-client')
const client = new ApolloClient()

错误信息:

TypeError: ApolloClient is not a constructor

Package.json:

{
...

"dependencies": {
"apollo-client": "^2.4.13",
"graphql": "^14.1.1",
"graphql-tag": "^2.10.1"
},
}

Node :v8.9.4

我在谷歌上搜索了一段时间,人们遇到这个问题主要是因为 ApolloClient 不再在 react-apollo 中。你必须从'apollo-client'导入它

我从 apollo-client 导入为 const ApolloClient = require('apollo-client')

有什么想法吗?谢谢!

最佳答案

如果您正在使用require,您可以像这样导入它:

const ApolloClient = require('apollo-client').default

或者像这样

const { ApolloClient } = require('apollo-client')

否则,您将导入整个模块,它本身不是构造函数。

关于node.js - ApolloClient 不是构造函数(带有 nodejs 的 apollo-client),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54688108/

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