馃悰 BUG
When using parcel in a react project that also uses aws-amplify, parcel fails to resolve the dependency for amazon-cognito-identity-js even though it is correctly placed in node_modules/ by yarn.
Here is a repository with a minimal setup to reproduce the problem: https://github.com/dfrkp/parcel-test
A bundle is created even if aws-amplify is used.
$ yarn start [13:38:01]
yarn run v1.5.1
$ parcel index.html
Server running at http://localhost:1234
馃毃 /Users/user/Development/parcel-test/node_modules/aws-amplify/lib/Common/Facet.js:20:22: Cannot resolve dependency 'amazon-cognito-identity-js'
18 | var AWS = require("aws-sdk/global");
19 | exports.AWS = AWS;
> 20 | var Cognito = require("amazon-cognito-identity-js");
| ^
21 | exports.Cognito = Cognito;
22 | var Pinpoint = require("aws-sdk/clients/pinpoint");
23 | exports.Pinpoint = Pinpoint;
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.6.2 |
| Node | 9.9 |
| Yarn | 1.5.1
| Operating System | macOS |
This happens because parcel tries to load the module from es/index.js instead of lib/index.js, see https://github.com/parcel-bundler/parcel/blob/fc041d03c36bf41ea73c398e8d177de1a456e796/src/Resolver.js#L220-L224
However, the es folder doesn't exist.
IMO this is a bug from amazon-cognito-identity-js since that folder should be there. There is an issue reported there about this: https://github.com/aws/aws-amplify/issues/517
Parcel could try to see if the entry specified by "module" or "jsnext:main" exists or not first but I feel like that's not necessary.
If you're going the extra mile, reporting the actual missing file (and why it was used) would be better than falling back to the first existing file, if that's what you meant.
A stronger motivation for fixing this would be monorepos - where it would make it clear you just haven't built yet, rather than that resolution is broken.
Most helpful comment
This happens because parcel tries to load the module from
es/index.jsinstead oflib/index.js, see https://github.com/parcel-bundler/parcel/blob/fc041d03c36bf41ea73c398e8d177de1a456e796/src/Resolver.js#L220-L224However, the
esfolder doesn't exist.IMO this is a bug from
amazon-cognito-identity-jssince that folder should be there. There is an issue reported there about this: https://github.com/aws/aws-amplify/issues/517Parcel could try to see if the entry specified by "module" or "jsnext:main" exists or not first but I feel like that's not necessary.