yarn icon indicating copy to clipboard operation
yarn copied to clipboard

An unexpected error occurred: Request failed \"404 Not Found\"".

Open DannyBrown-xx opened this issue 9 years ago • 98 comments

Do you want to request a feature or report a bug? Bug

What is the current behavior? I have a package which only depends on modules from the npmjs repository. They are predominantly public repositories, however 5 of them are private repositories scoped using an @ symbol. Again, these are hosted on npmjs.

Up until some time today all of them would download an install without issue. However, something has changed and now one of them fails to install with the following error:

error An unexpected error occurred: "http://registry.npmjs.org/@pepperhq/hmac-http-authentication/-/hmac-http-authentication-0.1.2.tgz: Request failed \"404 Not Found\"".

As I stated previously, the other private repositories (all within the same @ scope) download and install as intended. This leads me to think this isn't an authentication issue.

My .npmrc which is in the root of my project and contains my _authToken looks like this:

//registry.npmjs.org/:_authToken=TOKEN_HERE

I have already completed the following activities:

  1. Logging in using npm login again to get a fresh accessToken
  2. Ensuring the package name is correct (I copied it from the npm website just to be sure)
  3. Running rm -rf node_modules && rm yarn.lock && yarn cache clean
  4. Removing the offending package from my package.json and attempting to re yarn add it
  5. Attempting to run the equivalent npm install --save command. This worked.

If the current behavior is a bug, please provide the steps to reproduce. As I am unsure of the cause I am unsure how to reproduce. Am willing to discuss further on Discord or in comments on this Issue.

What is the expected behavior? I expect Yarn to install all of my private repositories from npmjs

Please mention your node.js, yarn and operating system version. Taken from yarn-error.log

Yarn version: 
  0.20.3

Node version: 
  6.9.5

Platform: 
  darwin x64

DannyBrown-xx avatar Feb 21 '17 00:02 DannyBrown-xx

As an aside, the package clearly does exist and yarn is clearly accessing the package in some way because the url contains the version number it is attempting to retrieve.

DannyBrown-xx avatar Feb 21 '17 00:02 DannyBrown-xx

Having ran some more tests, I've found that the same package fails to install from other repositories that require it when using Yarn. However, it works fine when using npm.

This leads me to think it isn't my repository specific config. Could it be something to do with the name of the package tripping Yarn up, or the url encoding or something?

Clutching at straws here, but hopefully this might bump someone in the right direction

DannyBrown-xx avatar Feb 21 '17 01:02 DannyBrown-xx

I fixed this: I simply re-published the offending package with a new version number.

I have no idea why that fixed it.

I will leave this here in case it aids debugging.

DannyBrown-xx avatar Feb 21 '17 01:02 DannyBrown-xx

I'm experiencing the same issue. This seems to happen randomly and is often resolved by simply retrying the build.

bjrnt avatar Feb 24 '17 06:02 bjrnt

We're also experiencing the exact same issue. Some private modules work some do not; all the same @scope.

rogchap avatar Mar 01 '17 05:03 rogchap

We just experienced the same issue. Some more context here in the hopes that it might help

  • We were running yarn in our CI (Drone), which runs in ephemeral Docker containers [Alpine Linux]
  • The issue occurred in only ONE of our services building, whereas nothing went wrong with the other services, even though they have the exact same dependency tree (!)
  • a manual install on my Mac for the same repo yielded no issues at all (!)
  • the issue was limited to a single private package

As mentioned above as workaround, publishing a new version of the package resolved the issue.

Unfortunately, I was unable to obtain a detailed yarn-error.log as the containers are destroyed immediately after a failed build. If anyone else has this issue, could you try it again with a verbose install and throw the log in here?

hilkeheremans avatar Mar 01 '17 10:03 hilkeheremans

I am seeing the same issue. I'm using a docker image in circleci 2.0 and having some unrelated issues that I'm debugging locally (compilation difference on cci vs local).

  • when I yarn on the host OSX machine, everything works.
  • when I yarn on the container (Ubuntu), I get the error.
  • when I yarn on the ^^container (Ubuntu) running on circleci 2.0 infrastructure, it works.

I have setup .npmrc etc. It's really a head-scratcher that it doesn't work for me on a locally running container.

Verbose didn't provide me with any information that I can spot:

root@2adc7c09ff9a:~/af/spec/dummy# yarn --pure-lockfile --ignore-optional
yarn install v0.21.3
[1/4] Resolving packages...
[2/4] Fetching packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/@alienfast/build/-/build-2.0.38.tgz: Request failed \"404 Not Found\"".
info If you think this is a bug, please open a bug report with the information provided in "/root/af/spec/dummy/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
root@2adc7c09ff9a:~/af/spec/dummy# yarn --pure-lockfile --ignore-optional --verbose
yarn install v0.21.3
verbose 0.178 current time: 2017-03-01T20:22:52.715Z
[1/4] Resolving packages...
[2/4] Fetching packages...
verbose 0.798 Performing "GET" request to "https://registry.yarnpkg.com/@alienfast/build/-/build-2.0.38.tgz".
verbose 0.861 Performing "GET" request to "https://registry.yarnpkg.com/@alienfast/ui/-/ui-1.0.34.tgz".
verbose 0.894 Performing "GET" request to "https://registry.yarnpkg.com/react-relay/-/react-relay-0.10.0.tgz".
verbose 0.895 Performing "GET" request to "https://registry.yarnpkg.com/react-dom/-/react-dom-15.4.2.tgz".
verbose 0.919 Performing "GET" request to "https://registry.yarnpkg.com/eslint/-/eslint-3.15.0.tgz".
verbose 0.941 Performing "GET" request to "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.39.0.tgz".
verbose 0.951 Performing "GET" request to "https://registry.yarnpkg.com/@alienfast/material-ui/-/material-ui-0.16.87.tgz".
verbose 0.966 Performing "GET" request to "https://registry.yarnpkg.com/@alienfast/react-formal/-/react-formal-0.24.7.tgz".
verbose 1.003 Performing "GET" request to "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.23.0.tgz".
verbose 1.103 Performing "GET" request to "https://registry.yarnpkg.com/graphql/-/graphql-0.9.1.tgz".
verbose 1.178 Performing "GET" request to "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz".
verbose 1.206 Performing "GET" request to "https://registry.yarnpkg.com/material-ui/-/material-ui-0.16.7.tgz".
verbose 1.249 Performing "GET" request to "https://registry.yarnpkg.com/react-i18next/-/react-i18next-2.2.0.tgz".
verbose 1.261 Performing "GET" request to "https://registry.yarnpkg.com/react-relay-network-layer/-/react-relay-network-layer-1.4.0.tgz".
verbose 1.272 Performing "GET" request to "https://registry.yarnpkg.com/react-router/-/react-router-3.0.2.tgz".
verbose 1.696 Performing "GET" request to "https://registry.yarnpkg.com/react-router-relay/-/react-router-relay-0.13.5.tgz".
verbose 1.764 Performing "GET" request to "https://registry.yarnpkg.com/react-sizeme/-/react-sizeme-2.2.0.tgz".
verbose 2.063 Performing "GET" request to "https://registry.yarnpkg.com/recompose/-/recompose-0.22.0.tgz".
verbose 2.144 Error: https://registry.yarnpkg.com/@alienfast/build/-/build-2.0.38.tgz: Request failed "404 Not Found"
    at Request.handleRequestError (/root/.yarn/lib/fetchers/tarball-fetcher.js:231:20)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:189:7)
    at Request.onRequestResponse (/root/.yarn/node_modules/request/request.js:986:10)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:189:7)
    at HTTPParser.parserOnIncomingClient (_http_client.js:522:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
    at TLSSocket.socketOnData (_http_client.js:411:20)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:189:7)
error An unexpected error occurred: "https://registry.yarnpkg.com/@alienfast/build/-/build-2.0.38.tgz: Request failed \"404 Not Found\"".
info If you think this is a bug, please open a bug report with the information provided in "/root/af/spec/dummy/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
root@2adc7c09ff9a:~/af/spec/dummy# cat ~/.npmrc
registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
root@2adc7c09ff9a:~/af/spec/dummy# echo $NPM_TOKEN
xxxxx-xxxx-xxxx-xxxx-xxxxxxxx

rosskevin avatar Mar 01 '17 20:03 rosskevin

Same here, it works locally on OSX but not on the CircleCI container (circleci 1.0).

I tried to yarn cache clean - afterwards a different package failed installation.

It happens with yarn 0.18.1 as well as 0.21.3 - so maybe something changed in the yarnpkg registry configuration? Or, since I think everyone in the comments here is using CircleCI in the problem-scenario, it's an issue with CircleCI configuration?

flipace avatar Mar 02 '17 09:03 flipace

So, we think we've managed to solve the problem; would be keen to see if it works for others: We had to make a slight change to .npmrc which makes little sense why this works:

registry=http://registry.npmjs.org/
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
@ourscope:registry=https://registry.npmjs.org/

Thing to note is that we required both normal registry AND one for our private scoped registry. Just make sure you change @ourscope with your own.

Let me know if this helps anyone.

rogchap avatar Mar 02 '17 11:03 rogchap

@rogchap i just tried your solution but still see the same problem as before :(

we have a hyphen in our scope name, maybe that could be the culprit?

registry=http://registry.npmjs.org/
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
@our-scope:registry=https://registry.npmjs.org/

flipace avatar Mar 02 '17 13:03 flipace

@rogchap this workaround didn't have any effect on our situation.

root@f41305331cb8:~/af/spec/dummy# cat ~/.npmrc
registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
@alienfast:registry=https://registry.npmjs.org/

rosskevin avatar Mar 02 '17 15:03 rosskevin

Confirmed it fails with 0.20.4 and 0.21.3. Given that this has also been working for me without a problem, I'm curious if something has changed on the server side to cause this. This certainly now seems like a bug.

rosskevin avatar Mar 02 '17 15:03 rosskevin

  • I just deployed new versions of the 'offending' scoped modules and it made no difference, same error.
  • I ran npm install and have no problems fetching the modules in the problem environment

rosskevin avatar Mar 02 '17 20:03 rosskevin

So, not fixed for me...again.

I had another private module give me the 404 message, even though it seems to resolve the correct version (must be reading something correctly somewhere), and seems to try and download the same tar url as NPM.

This time I REMOVED the registries (except the auth one) in .npmrc to get it to work!

There is no consistency at all, randomly "playing" with .npmrc seems to temporarily work.

I'm trying to promote Yarn, but every engineer in our company (rightly) says that Yarn is "not stable", "un usable", "not reliable", "doesn't work with private modules", "fails on the CI server" etc etc.

I wonder if the Private NPM registry is doing something "funky" with the user-agent!?? <- Wild guess.

rogchap avatar Mar 05 '17 22:03 rogchap

In order to better understand this we may need some input from core contributors. @bestander, any insights?

hilkeheremans avatar Mar 06 '17 07:03 hilkeheremans

We don't use private packages much so this feature has less eyes on. Afaik most of the issues were fixed by the community. This is a great opportunity to try to fix it. I don't think npm registry would do something with the response based on UA, most likely the token is not passed at all for some reason.

bestander avatar Mar 06 '17 19:03 bestander

Okay, so I forked yarn and fiddled around a bit. It seems like it loses the token before it fetches the tarball or rather after the first request is sent...

yarn add v0.23.0-0
verbose 0.227 current time: 2017-03-06T20:25:18.877Z
info No lockfile found.
[1/4] Resolving packages...
⠁ { authorization: 'Bearer MY_TOKEN_IS_HERE' } <<<<<----- here it uses my token for the request
verbose 0.409 Performing "GET" request to "https://registry.npmjs.org/@ovos-media%2flib-director".
verbose 1.306 Request "https://registry.npmjs.org/@ovos-media%2flib-director" finished with status code 200.
{} <--- token is gone
verbose 1.316 Performing "GET" request to "https://registry.npmjs.org/bluebird".
{} <--- token is gone
verbose 1.318 Performing "GET" request to "https://registry.npmjs.org/jwt-decode".
verbose 1.531 Request "https://registry.npmjs.org/bluebird" finished with status code 200.
verbose 1.572 Request "https://registry.npmjs.org/jwt-decode" finished with status code 200.
[2/4] Fetching packages...
https: /@ovos-media/lib-director/-/lib-director-0.4.1.tgz https://registry.yarnpkg.com/@ovos-media/lib-director/-/lib-director-0.4.1.tgz
{} <--- token is gone
verbose 1.597 Performing "GET" request to "https://registry.yarnpkg.com/@ovos-media/lib-director/-/lib-director-0.4.1.tgz".
verbose 2.663 Error: https://registry.yarnpkg.com/@ovos-media/lib-director/-/lib-director-0.4.1.tgz: Request failed "404 Not Found"
    at Request.res (/home/ubuntu/yarn/lib/fetchers/tarball-fetcher.js:232:20)
    at emitOne (events.js:90:13)
    at Request.emit (events.js:182:7)
    at Request.onRequestResponse (/home/ubuntu/yarn/node_modules/request/request.js:986:10)
    at emitOne (events.js:90:13)
    at ClientRequest.emit (events.js:182:7)
    at HTTPParser.parserOnIncomingClient (_http_client.js:469:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:103:23)
    at TLSSocket.socketOnData (_http_client.js:359:20)
    at emitOne (events.js:90:13)
error An unexpected error occurred: "https://registry.yarnpkg.com/@ovos-media/lib-director/-/lib-director-0.4.1.tgz: Request failed \"404 Not Found\"".

When I explicitly set the authorization header in the npm-registry.js before the request is sent, everything works fine. So there seems to be some bug in yarn and not on the server side.

EDIT:

Okay, so after further inspection, this problem occurs because the check whether the authorization header should be set returns false in npm-registry.js -> https://github.com/yarnpkg/yarn/pull/2598/files#diff-b053bee294c216269844e5874039b6caR62 And this, in turn, happens because it compares the yarnpkg registry proxy with the npmjs registry.

https://registry.yarnpkg.com/@ovos-media/lib-director/-/lib-director-0.4.1.tgz https://registry.npmjs.org/

flipace avatar Mar 06 '17 20:03 flipace

Okay, so i figured out how to fix this issue for us without a change to yarns source code. It's basically what @rogchap posted but (in our case) in the other direction:

registry=https://registry.npmjs.org/
@ovos-media:registry=https://registry.yarnpkg.com/
//registry.npmjs.org/:_authToken=your-auth-token

OR alternatively completely getting rid of registry:

//registry.npmjs.org/:_authToken=your-auth-token

This seems to work because then yarn does not use different registries for the package in question to fetch info and tarballs. However, I'm unsure as to why yarn mixes these two and I think that maybe the check for the auth token could be changed/improved somehow.

flipace avatar Mar 06 '17 21:03 flipace

What is the next step? Document the workaround or make changes to Yarn?

bestander avatar Mar 07 '17 15:03 bestander

I've been trying out every possible combination for the past few hours and I think it's safe to say that there is no reliable workaround for this issue. @flipace any idea if this is something that can be fixed easily? Both of your methods do not work for me :(.

pleunv avatar Mar 09 '17 21:03 pleunv