【问题标题】:Apollo-client with parcel warnings带有包裹警告的 Apollo 客户端
【发布时间】:2019-03-27 17:15:34
【问题描述】:

一直在尝试为我的 react 应用程序设置带有包裹的 apollo-client。一切正常,但在控制台中,有很多关于我的 CI 管道中 node_modules/apollo-client 中缺少源文件的警告。

已尝试清除纱线缓存,删除 node_modules 并重新安装。但警告是持久的。我可能遗漏了 parcel 或 babel 配置的一些东西。找到了一些提示,但它们是特定于 webpack 的。

以下是日志:

⚠️  Could not load source file "../../src/data/store.ts" in source map of "../node_modules/apollo-client/data/store.js".
⚠️  Could not load source file "../../src/util/Observable.ts" in source map of "../node_modules/apollo-client/util/Observable.js"
.
⚠️  Could not load source file "../../src/core/QueryManager.ts" in source map of "../node_modules/apollo-client/core/QueryManager.js".
⚠️  Could not load source file "../../src/data/mutations.ts" in source map of "../node_modules/apollo-client/data/mutations.js".
⚠️  Could not load source file "../../src/scheduler/scheduler.ts" in source map of "../node_modules/apollo-client/scheduler/scheduler.js".
⚠️  Could not load source file "../../src/data/queries.ts" in source map of "../node_modules/apollo-client/data/queries.js".
⚠️  Could not load source file "../../src/errors/ApolloError.ts" in source map of "../node_modules/apollo-client/errors/ApolloError.js".
⚠️  Could not load source file "../../src/core/networkStatus.ts" in source map of "../node_modules/apollo-client/core/networkStatus.js".
⚠️  Could not load source file "../src/ApolloClient.ts" in source map of "../node_modules/apollo-client/ApolloClient.js".
⚠️  Could not load source file "../../src/core/ObservableQuery.ts" in source map of "../node_modules/apollo-client/core/ObservableQuery.js".
⚠️  Could not load source file "../src/index.ts" in source map of "../node_modules/apollo-client/index.js".
⚠️  Could not load source file "../../src/core/types.ts" in source map of "../node_modules/apollo-client/core/types.js"

【问题讨论】:

标签: apollo react-apollo parceljs


【解决方案1】:

造成这个问题的原因是 parceljs 试图从 source maps 中找到源文件。这些文件是否存在,您只需查看分布式文件夹即可检查。我不知道为什么会显示警告。但是,您并不孤单,请参阅:https://github.com/parcel-bundler/parcel/issues/2185

要抑制警告,您可以使用 CLI 选项:--log-level 1。但是请记住,您将禁止所有警告,我不建议这样做!

如果有人遇到错误:Property name expected type of string but got null,您可以使用以下选项来解决该问题:npx parcel watch ./server/src/YOUR_SOURCE_INDEX --out-dir ./YOUR_DESTINATION --no-hmr --target node

还有一个问题:https://github.com/apollographql/apollo-server/issues/2453

【讨论】:

    【解决方案2】:

    在为我的 react 应用程序设置带有包裹的 apollo-client 时遇到了同样的问题(并且我没有使用 typescript)。虽然我收到相同的警告,但该应用程序确实可以编译并且可以正常工作。如果我正确理解了情况,parcel 正在尝试从 node_modules 解析源映射,但在 apollo-client 的情况下无法正确找到它们。

    抑制警告的简单解决方法是将简单的 tsconfig.json 文件添加到项目根目录:

    ./tsconfig.js

    {
      "exclude": [
        "./node_modules",
        "**/*.spec.ts"
      ]
    }
    

    【讨论】:

    • 谢谢,我必须把它与解决问题相关联。 "./node_modules"
    • 它不起作用。您可能没有在构建之间删除缓存。删除缓存并再次构建后,即使使用此解决方案它仍然无法正常工作
    猜你喜欢
    • 2018-04-13
    • 2020-08-31
    • 2019-01-18
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 2018-05-12
    相关资源
    最近更新 更多