13

一直在尝试为我的反应应用程序设置带有包裹的 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"
4

2 回答 2

4

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

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

./tsconfig.js

{
  "exclude": [
    "./node_modules",
    "**/*.spec.ts"
  ]
}
于 2018-11-25T15:42:21.603 回答
1

造成这个问题的原因是 parceljs 试图从源映射中找到源文件。这些文件是否存在,您只需查看分布式文件夹即可检查。我不知道为什么会显示警告。但是,您并不孤单,请参阅: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

于 2019-08-11T14:07:21.783 回答