【发布时间】:2021-01-29 09:23:34
【问题描述】:
我刚刚将一个 Gatsby 项目转换为 Typescript,由于这个错误,现在无法运行开发服务器:
There was an error compiling the html.js component for the development server.
See our docs page on debugging HTML builds for help https://gatsby.dev/debug-html Invariant Violation:
10 | function InvariantError(message) {
11 | if (message === void 0) { message = genericMessage; }
> 12 | var _this = _super.call(this, typeof message === "number"
| ^
13 | ? genericMessage + ": " + message + " (see https://github.com/apollographql/invariant-packages)"
14 | : message) || this;
15 | _this.framesToPop = 1;
WebpackError: Invariant Violation:
- invariant.esm.js:12
node_modules/ts-invariant/lib/invariant.esm.js:12:1
- checkFetcher.js:4
node_modules/@apollo/client/link/http/checkFetcher.js:4:77
- createHttpLink.js:15
node_modules/@apollo/client/link/http/createHttpLink.js:15:17
- apolloClient.ts:3
src/utils/apolloClient.ts:3:36
这是我的 apolloClient.ts 和各种实验:
import { ApolloClient, InMemoryCache, createHttpLink } from '@apollo/client'
export const link = createHttpLink({
uri: 'https://48p1r2roz4.sse.codesandbox.io'
})
export const apolloClient = new ApolloClient({
uri: 'https://48p1r2roz4.sse.codesandbox.io',
cache: new InMemoryCache()
})
// export const apolloClient = new ApolloClient({
// link,
// //uri: process.env.GATSBY_GRAPHQL_ENDPOINT,
// cache: new InMemoryCache()
// })
谷歌搜索建议两件事:
- 混合使用 import/require 可能会发生 webpack 不变错误。这可能不是问题 - 如果我将文件替换为:
export const apolloClient = ''
一切顺利。
我尝试了各种链接/网址配置等...不行。
想法?
【问题讨论】:
标签: typescript webpack gatsby apollo react-apollo