apollo-client: [apollo-cache-inmemory] ESLint problems importing InMemoryCache
Intended outcome:
After installing apollo-cache-inmemory
, import and use InMemoryCache
Actual outcome: Errors in ESlint and when starting application.
Line 2: Unable to resolve path to module 'apollo-cache-inmemory' import/no-unresolved
Line 2: Missing file extension for "apollo-cache-inmemory" import/extensions
How to reproduce the issue:
Install the package and import InMemoryCache
using
import { InMemoryCache } from 'apollo-cache-inmemory';
Version
- “apollo-cache-inmemory”: “^1.1.1”
- “apollo-client”: “^2.0.3”
- “apollo-link”: “^1.0.3”
- “apollo-link-context”: “^1.0.1”
- “apollo-link-http”: “^1.2.0”
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 23
- Comments: 18 (12 by maintainers)
@jbaxleyiii Nothing more comes to my mind at this time, just the
sideEffects
tip I mentioned above. As for the fix, we can actually do without./
in themain
/module
/jsnext:main
/typings
fields, because they’re implicitly relative: i.e.lib/index
orlib/index.js
should be enough.Actually, the reason for this issue is that path for
jsnext:main
is wrong in all the the packages, e.g.:https://github.com/apollographql/apollo-client/blob/37e6f9b8adc1bf2fc12bb8c3cb5c2aa898702ce2/packages/apollo-cache-inmemory/package.json#L12-L15
You can see that it’s missing a
.
in front. This causes the eslint rule to resolve it from the root instead of relative to the package.The bugs were introduced in #2466. Another issue is that MapCache, which is not re-exported is now unusable from Node (only when building with Webpack) since it’s not exposed in index (on purpose, I didn’t want to add it to the bundle, since it would increase it’s size).
To make #2466 even more solid, all the package.json’s should also include
sideEffects: false
. Webpack 4 will use that information to truly tree-shake re-exported properties. Right now #2466 won’t really have much of an effect, because re-exported properties are not properly tree-shaken in Webpack.👋 @glennblock nvm … all good 👉 https://github.com/apollographql/apollo-client/pull/2648
@jbaxleyiii I did some testing and it seems ESLint doesn’t care about package.json’s
main
field. If I setmain: "./lib/index.js"
ESLint warns thatapollo-cache-inmemory/index.js
is missing. Which is true but because there is no./index.js
this is why we havemain
in package.json to point to the entry file. I could set there any path, it still won’t work.We could publish
apollo-cache-inmemory
the same way we do withapollo-client
, meaning all the files would be in root directory of a package. I checked and it solves the issue.Wrong Glenn 😃
I don’t think so. Probably has something to do with this PR: https://github.com/apollographql/apollo-client/pull/2466