角度 16 中的 Apollo-angular 产生反应依赖性问题

Apollo-angular producing react dependency issue in angular 16

提问人:Masum Mollik 提问时间:11/14/2023 更新时间:11/14/2023 访问量:33

问:

我正在将 apollo-client 用于 angular 16

    "@apollo/client": "^3.8.7",
    "apollo-angular": "^5.0.2",
    "graphql": "^16.8.1",

这是 app.module.ts 中数组的集合providers

  providers: [
    {
      provide: APOLLO_OPTIONS,
      useFactory(httpLink: HttpLink) {
        return {
          cache: new InMemoryCache(),
          link: httpLink.create({
            uri: uri,
          }),
          defaultOptions: { 
            watchQuery: {
              fetchPolicy: 'cache-and-network',
              errorPolicy: 'ignore',
            },
          }
        };
      },
      deps: [HttpLink],
    }
  ],

但是我收到此构建错误消息。

./node_modules/@apollo/client/react/context/ApolloConsumer.js:2:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/context'

./node_modules/@apollo/client/react/context/ApolloContext.js:1:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/context'

./node_modules/@apollo/client/react/context/ApolloProvider.js:3:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/context'

./node_modules/@apollo/client/react/hooks/internal/__use.js:2:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks/internal'

./node_modules/@apollo/client/react/hooks/internal/useDeepMemo.js:1:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks/internal'

./node_modules/@apollo/client/react/hooks/internal/useIsomorphicLayoutEffect.js:1:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks/internal'

./node_modules/@apollo/client/react/hooks/useApolloClient.js:2:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

./node_modules/@apollo/client/react/hooks/useBackgroundQuery.js:2:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

./node_modules/@apollo/client/react/hooks/useFragment.js:2:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

./node_modules/@apollo/client/react/hooks/useLazyQuery.js:2:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

./node_modules/@apollo/client/react/hooks/useMutation.js:2:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

./node_modules/@apollo/client/react/hooks/useQuery.js:3:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

./node_modules/@apollo/client/react/hooks/useReactiveVar.js:1:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

./node_modules/@apollo/client/react/hooks/useReadQuery.js:1:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

./node_modules/@apollo/client/react/hooks/useSubscription.js:2:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

./node_modules/@apollo/client/react/hooks/useSuspenseQuery.js:2:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

./node_modules/@apollo/client/react/hooks/useSyncExternalStore.js:2:0-31 - Error: Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/Workstation/rmlDAG/rmldag-frontend/node_modules/@apollo/client/react/hooks'

Error: node_modules/@apollo/client/react/context/ApolloConsumer.d.ts:1:24 - error TS2307: Cannot find module 'react' or its corresponding type declarations.

1 import * as React from "react";
                         ~~~~~~~


Error: node_modules/@apollo/client/react/context/ApolloContext.d.ts:1:24 - error TS2307: Cannot find module 'react' or its corresponding type declarations.

1 import * as React from "react";
                         ~~~~~~~


Error: node_modules/@apollo/client/react/context/ApolloProvider.d.ts:1:24 - error TS2307: Cannot find module 'react' or its corresponding type declarations.

1 import * as React from "react";
                         ~~~~~~~


Error: node_modules/@apollo/client/react/ssr/RenderPromises.d.ts:1:23 - error TS2688: Cannot find type definition file for 'react'.

1 /// <reference types="react" />
                        ~~~~~


Error: node_modules/@apollo/client/react/ssr/RenderPromises.d.ts:15:62 - error TS2503: Cannot find namespace 'React'.

15     addQueryPromise(queryInstance: QueryData, finish?: () => React.ReactNode): React.ReactNode;
                                                                ~~~~~


Error: node_modules/@apollo/client/react/ssr/RenderPromises.d.ts:15:80 - error TS2503: Cannot find namespace 'React'.

15     addQueryPromise(queryInstance: QueryData, finish?: () => React.ReactNode): React.ReactNode;
                                                                                  ~~~~~


Error: node_modules/@apollo/client/react/ssr/RenderPromises.d.ts:16:131 - error TS2307: Cannot find module 'react' or its corresponding type declarations.

16     addObservableQueryPromise<TData, TVariables extends OperationVariables>(obsQuery: ObservableQuery<TData, TVariables>): import("react").ReactNode;
                                                                                                                                     ~~~~~~~


Error: node_modules/@apollo/client/react/ssr/getDataFromTree.d.ts:1:24 - error TS2307: Cannot find module 'react' or its corresponding type declarations.

1 import * as React from "react";
                         ~~~~~~~


Error: node_modules/@apollo/client/react/ssr/renderToStringWithData.d.ts:1:35 - error TS2307: Cannot find module 'react' or its corresponding type declarations.

1 import type { ReactElement } from "react";
                                    ~~~~~~~


Error: node_modules/@apollo/client/react/types/types.d.ts:1:32 - error TS2307: Cannot find module 'react' or its corresponding type declarations.

1 import type { ReactNode } from "react";
                                 ~~~~~~~


Error: node_modules/@apollo/client/react/types/types.d.ts:126:63 - error TS2503: Cannot find namespace 'JSX'.

126     children?: null | ((result: SubscriptionResult<TData>) => JSX.Element | null);
                                                                  ~~~


角度 apollo-client apollo-angular

评论


答:

-1赞 Masum Mollik 11/14/2023 #1

您可以导入 from 来获取除依赖 React 的东西之外的所有内容,而不是 import from 。@apollo/client@apollo/client/core