Do you want to request a feature or report a bug?
More like Yarn infrastructure misconfig.
What is the current behavior?
Yarn fails to fetch find-my-way dependency on some hosts.
If the current behavior is a bug, please provide the steps to reproduce.
Depending on the region where you are, it may fail or not. Steps to reproduce:
yarn init -y
yarn add find-my-way
What is the expected behavior?
...
success Saved lockfile.
success Saved 5 new dependencies.
...
What is the actual behavior?
On some hosts it is as expected. On some Yarn produces the following message:
...
error Received malformed response from registry for "find-my-way". The registry may be down.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
...
Please mention your node.js, yarn and operating system version.
Node: 10.15.1
Yarn: 1.13.0
OS: Debian 9.8
I've tried to debug the issue on the working and failing hosts, comparing the actual network responses. On the failing one, the body of the JSON fetched is indeed malformed, here it is https://codebeautify.org/online-json-editor/cba63a53. Yarn can't parse it so it shows the Received malformed response from registry error.
I compared the failing response with the successful one and the only difference I spotted is the cf-ray header.
cf-ray of the successful response is: 4af3fbb8baddXXXX-BRU (Brussels), whereas for the failing one it is 4af3e42e2cfeXXXX-DUB (Dublin).
That being said, I suspect CloudFlare cache is the culprit. Could you please take a look into this and refresh the cache in Dublin?
We are having another issue which may have the same root cause.
Since yesterday we can not fetch the acorn package from our servers at Dublin when we want to install our app:
...
[3/5] Fetching packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/acorn/-/acorn-5.4.1.tgz: unexpected end of file".
info If you think this is a bug, please open a bug report with the information provided in "/var/www/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
...
However, doing the same command on another host in Paris works perfectly:
...
[3/5] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/5] Linking dependencies...
...
We think there is some issue with the cache servers in Dublin. Could the cache servers in Dublin be checked?
Node version: 8.9.4
Yarn version: 1.10.1
OS: Debian Jessie (Docker)
Temporary "fix" for those who affected by this, until this is fixed. You can use selective dependency resolution mechanism of Yarn.
Add something like this to your package.json (example):
"resolutions": {
"fastify/find-my-way": "https://github.com/delvedor/find-my-way#2.0.1"
}
In this particular case the find-my-way package's version 2.0.1 will be fetched directly from GitHub, if it is a direct dependency of fastify.
This way Yarn will not try to get JSON from the https://registry.yarnpkg.com/find-my-way, so the issue will be mitigated.
More info about selective dependency resolution: https://yarnpkg.com/lang/en/docs/selective-version-resolutions/
NPM guys have reported that the issue is resolved now. Corresponding thread at npm.community: https://npm.community/t/error-unexpected-token-in-json-at-position/5671
"find-my-way" package is now getting successfully fetched via NPM/Yarn, so I believe it's resolved now, so I'm proceeding to close this issue.