codesandbox / codesandbox-client

An online IDE for rapid web development
https://codesandbox.io
Other
13.08k stars 2.28k forks source link

"Deploy to Netlify" returns 401 error #4772

Closed linqcan closed 3 years ago

linqcan commented 4 years ago

🐛 bug report

Description of the problem

When using the "Deploy to Netlify" button, the created deploy at Netlify does nothing and never finishes.

image

How has this issue affected you? What are you trying to accomplish?

Unable to deploy my sandbox.

The Netlify has referred me to you, see this thread: https://community.netlify.com/t/deploy-from-codesandbox-doesnt-work/21200/6

Link to sandbox: [link]() (optional)

https://codesandbox.io/s/hungry-kirch-3nh32

Your Environment

Software Name/Version
Сodesandbox a814c4203
Browser Chrome 84.0.4147.135 (Official Build) (64-bit) (cohort: Stable)
Operating System Windows
SaraVieira commented 4 years ago

Hey!

Do you get any errors in the logs modal?

I tried to fork it and deploy it and it worked

https://csb-6tvdc.netlify.app/

linqcan commented 4 years ago

This:

Start Build... 
npm install
> core-js@2.6.11 postinstall /codebuild/output/src629601547/src/package/node_modules/babel-runtime/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
> core-js@3.6.5 postinstall /codebuild/output/src629601547/src/package/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
added 1623 packages from 832 contributors and audited 1627 packages in 30.156s
found 2 vulnerabilities (1 low, 1 high)
run `npm audit fix` to fix them, or `npm audit` for details
npm install netlify-cli -g
/usr/local/bin/ntl -> /usr/local/lib/node_modules/netlify-cli/bin/run
/usr/local/bin/netlify -> /usr/local/lib/node_modules/netlify-cli/bin/run
> netlify-cli@2.59.1 postinstall /usr/local/lib/node_modules/netlify-cli
> node ./scripts/postinstall.js
Success! Netlify CLI has been installed!
Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.
Next steps:
netlify init Connect or create a Netlify site from current directory
netlify deploy Deploy the latest changes to your Netlify site
For more information on the CLI run netlify help
Or visit the docs at https://cli.netlify.com
+ netlify-cli@2.59.1
added 1075 packages from 558 contributors in 47.997s
running build command
> react-typescript@1.0.0 build /codebuild/output/src629601547/src/package
> react-scripts build
The following changes are being made to your tsconfig.json file:
- compilerOptions.target to be suggested value: es5 (this can be changed)
- compilerOptions.allowJs to be suggested value: true (this can be changed)
- compilerOptions.skipLibCheck to be suggested value: true (this can be changed)
- compilerOptions.allowSyntheticDefaultImports to be suggested value: true (this can be changed)
- compilerOptions.forceConsistentCasingInFileNames to be suggested value: true (this can be changed)
- compilerOptions.module must be esnext (for import() and import/export)
- compilerOptions.moduleResolution must be node (to match webpack resolution)
- compilerOptions.resolveJsonModule must be true (to match webpack loader)
- compilerOptions.isolatedModules must be true (implementation limitation)
- compilerOptions.noEmit must be true
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
51.19 KB build/static/js/2.4ce150ac.chunk.js
794 B build/static/js/main.1998e12d.chunk.js
779 B build/static/js/runtime-main.9c7c50c1.js
The project was built assuming it is hosted at the server root.
You can control this with the homepage field in your package.json.
For example, add this to build it for GitHub Pages:
"homepage" : "http://myname.github.io/myapp",
The build folder is ready to be deployed.
You may serve it with a static server:
npm install -g serve
serve -s build
Find out more about deployment here:
bit.ly/CRA-deploy
netlify deploy
Deploying to main site URL...
- Hashing files...
✔ Finished hashing 11 files
- CDN diffing files...
✔ CDN requesting 6 files
- Uploading 6 files
› Warning: JSONHTTPError: Origin returned error code 401
› Warning:
› {
› "name": "JSONHTTPError",
› "status": 401,
› "json": {
› "code": 401,
› "message": "Origin returned error code"
› }
› }
›
JSONHTTPError: Unauthorized
echo 'Initial file upload deleted'
Initial file upload deleted

This from js console (could be unrelated): image

This is from Netlify: image

SaraVieira commented 4 years ago

Hey!

A 401 is a weird error we have gotten once, it means there is already a netlifly deploy with the same id as the sandbox you are trying to deploy :/

Can you please fork the sandbox and try again? You can then delete the original one

Sorry about the issue, this is really hard to test

linqcan commented 4 years ago

Forking it and deploying again does work.

You decide if you want to close this issue or keep it open to find the root cause.

SaraVieira commented 4 years ago

I am going to leave it open and rename the title to be more descriptive since I know it's a forbidden error

linqcan commented 4 years ago

@SaraVieira I managed to reproduce the error again by doing the following:

  1. Create a new React Sandbox
  2. Deploy it to Netlify
  3. Make a change to my sandbox
  4. Deploy it to Netlify again. (with the purpose to deploy my recent changes)
Start Build... 
npm install
> core-js@2.6.11 postinstall /codebuild/output/src840190658/src/package/node_modules/babel-runtime/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
> core-js@3.6.5 postinstall /codebuild/output/src840190658/src/package/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
added 1487 packages from 696 contributors and audited 1491 packages in 26.369s
found 5 vulnerabilities (1 low, 2 moderate, 2 high)
run `npm audit fix` to fix them, or `npm audit` for details
npm install netlify-cli -g
/usr/local/bin/ntl -> /usr/local/lib/node_modules/netlify-cli/bin/run
/usr/local/bin/netlify -> /usr/local/lib/node_modules/netlify-cli/bin/run
> netlify-cli@2.59.1 postinstall /usr/local/lib/node_modules/netlify-cli
> node ./scripts/postinstall.js
Success! Netlify CLI has been installed!
Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.
Next steps:
netlify init Connect or create a Netlify site from current directory
netlify deploy Deploy the latest changes to your Netlify site
For more information on the CLI run netlify help
Or visit the docs at https://cli.netlify.com
+ netlify-cli@2.59.1
added 1076 packages from 558 contributors in 28.024s
running build command
> react@1.0.0 build /codebuild/output/src840190658/src/package
> react-scripts build
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
39.88 KB build/static/js/2.32bdae52.chunk.js
762 B build/static/js/runtime~main.a8a9905a.js
335 B build/static/js/main.ee6685c3.chunk.js
118 B build/static/css/main.9b1431d8.chunk.css
The project was built assuming it is hosted at the server root.
You can control this with the homepage field in your package.json.
For example, add this to build it for GitHub Pages:
"homepage" : "http://myname.github.io/myapp",
The build folder is ready to be deployed.
You may serve it with a static server:
npm install -g serve
serve -s build
Find out more about deployment here:
https://bit.ly/CRA-deploy
netlify deploy
Deploying to main site URL...
- Hashing files...
✔ Finished hashing 12 files
- CDN diffing files...
✔ CDN requesting 6 files
- Uploading 6 files
› Warning: JSONHTTPError: Origin returned error code 401
› Warning:
› {
› "name": "JSONHTTPError",
› "status": 401,
› "json": {
› "code": 401,
› "message": "Origin returned error code"
› }
› }
›
JSONHTTPError: Unauthorized
echo 'Initial file upload deleted'
Initial file upload deleted

Am I using the feature correctly? If not, how am I supposed to (re-)deploy my changes to Netlify?

SaraVieira commented 4 years ago

Hey!

Did you change the name of the project on netlifly? This definitely should not happen

linqcan commented 4 years ago

No, I did nothing but clicking the "Deploy to Netlify" button (and claiming the site the first time).

SaraVieira commented 4 years ago

Then there must be a problem with the claiming it's not recognizing it's your site

I will take a look at this on monday

Sorry about the issue

tinypell3ts commented 4 years ago

I'm getting the same error as @linqcan. I didn't change the name. However, I added a custom domain to the sandbox on Netlify. If I fork the sandbox it works. If I deploy the forked sandbox again, I receive this:

Start Build... 
npm install
> core-js@2.6.11 postinstall /codebuild/output/src904427720/src/package/node_modules/babel-runtime/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
> core-js@3.6.5 postinstall /codebuild/output/src904427720/src/package/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
> core-js-pure@3.6.5 postinstall /codebuild/output/src904427720/src/package/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"
added 1600 packages from 756 contributors and audited 1604 packages in 26.985s
found 0 vulnerabilities
npm install netlify-cli -g
/usr/local/bin/ntl -> /usr/local/lib/node_modules/netlify-cli/bin/run
/usr/local/bin/netlify -> /usr/local/lib/node_modules/netlify-cli/bin/run
> netlify-cli@2.61.0 postinstall /usr/local/lib/node_modules/netlify-cli
> node ./scripts/postinstall.js
Success! Netlify CLI has been installed!
Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.
Next steps:
netlify init Connect or create a Netlify site from current directory
netlify deploy Deploy the latest changes to your Netlify site
For more information on the CLI run netlify help
Or visit the docs at https://cli.netlify.com
+ netlify-cli@2.61.0
added 1055 packages from 558 contributors in 29.725s
running build command
> portfolio@1.0.0 build /codebuild/output/src904427720/src/package
> react-scripts build
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
190.75 KB build/static/js/2.d0f14079.chunk.js
822 B build/static/js/main.ab7b51df.chunk.js
772 B build/static/js/runtime-main.19ccc7f6.js
472 B build/static/css/main.c3e9eb78.chunk.css
The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
You may serve it with a static server:
npm install -g serve
serve -s build
Find out more about deployment here:
bit.ly/CRA-deploy
netlify deploy
Deploying to main site URL...
- Hashing files...
✔ Finished hashing 13 files
- CDN diffing files...
✔ CDN requesting 8 files
- Uploading 8 files
› Warning: JSONHTTPError: Origin returned error code 401
› Warning:
› {
› "name": "JSONHTTPError",
› "status": 401,
› "json": {
› "code": 401,
› "message": "Origin returned error code"
› }
› }
›
JSONHTTPError: Unauthorized
echo 'Initial file upload deleted'
Initial file upload deleted

Thanks

hjylewis commented 4 years ago

This is happening to me too. I did claim the site but didn't change the name.

linqcan commented 4 years ago

Hi @SaraVieira! Any updates on this?

SaraVieira commented 3 years ago

Hey!

Not on a fix and I was not able to reproduce but it seems that when you hit a 401 it's because a site with that name already exists on Netlify so you will need to fork and then try to deploy again

I guess its a problem of Netlify being so big and we also having so many sandboxes :(

tacofueled commented 3 years ago

Same thing as others... the first deploy works and subsequent deploys get the 401. Is this the intended way to deploy updates to a sandbox on Netlify (go in and click deploy again from the rocket menu) or is there another process?

SaraVieira commented 3 years ago

Hey

Are you using the same account? This has only happened as I knew from trying to overwrite someone else's website

Also yes, this is the only way to deploy updates currently

tacofueled commented 3 years ago

I'll try it again and write down exact steps I take.

  1. Log in to CodeSandbox and Netlify. Both are linked to this GitHub account.
  2. Create a new sandbox with React template.
  3. Change some text on the page and save.
  4. Open rocket menu and click "Deploy to Netlify". I see the button gray out, a csb- ID generate and links to "Visit Site" and "Claim Site" show up.
  5. After a bit, a link to "View Logs" shows up.
  6. Click "View Logs". Log shows "Waiting for build to state..." then "Start build..." then normal npm messages.
  7. After a while, a green alert pops up telling me deploy was successful. Log ends with a website URL.
  8. Close the log window and click "View site". I get a working page on Netlify.
  9. Click "Claim site". Prompted on Netlify side to add CodeSandbox V2 projects to my account.
  10. Click "Add projects to Netlify dashboard". Taken to Netlify dashboard and site is visible.
  11. Go back to CodeSandbox tab and make another change to text on the page.
  12. Rocket menu is still open so click "Deploy to Netlify" again. "View logs" clears and button disables.
  13. Wait until "View logs" shows up again. Click it. Shows "Waiting for build to start", then "Start build".
  14. NPM messages start coming in. Gets to a point where it says "CDN requesting 6 files". At this point, Netlify dashboard shows a second deploy on the app with a yellow "Uploading" badge.
  15. Nothing apparently happening, but still waiting.
  16. After another few minutes, error messages show up in logs. The Netlify dashboard still shows "Uploading" and the app is not updated.

I'm attaching the logs from both deploy attempts, scrubbed of anything that looked potentially sensitive. I can send original logs if needed, either here if the scrubbed info isn't actually sensitive or via email if it is.

csb-log-scrubbed.txt

csb-log-2-scrubbed.txt

I hope this helps. Thank you for looking into it!

SaraVieira commented 3 years ago

Ohhh, I understand the issue

So what we do is that we never attach you as the owner of the site because you never log in to netlify on our platform so what happens is that when you claim the site that site now has an owner and we have no way of knowing that is you because we do not log you into netlify and so it returns back a 401 because it doesn't recognize you as the owner of the site you are trying to update.

This is definitely something we should work on by adding a netlifly login button but I hope this explanation makes sense

tacofueled commented 3 years ago

So to make sure I'm understanding... The redeployment to Netlify is only expected to work if the site hasn't been claimed? This is turns means no Netlify dashboard access to the site, right?

SaraVieira commented 3 years ago

Yes, when you claim it you loose access to updating it on CodeSandbox because you are not logged in to netlify

SaraVieira commented 3 years ago

Not saying it's a good system btw, it's a problem

github-actions[bot] commented 3 years ago

This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.

github-actions[bot] commented 3 years ago

This issue has been automatically closed because there wasn't any activity after the previous notice or the stale label wasn't removed.

OlaoyeVic commented 3 years ago

Hey!

A 401 is a weird error we have gotten once, it means there is already a netlifly deploy with the same id as the sandbox you are trying to deploy :/

Can you please fork the sandbox and try again? You can then delete the original one

Sorry about the issue, this is really hard to test

I'm sorry for bagging on the conversation, but please is there a way to change the domain of the codesandbox while deploying to netlify

JamesACS commented 3 years ago

Hey @OlaoyeVic - Be default Netlify deployments go to CodeSandbox Netlify account - you could request ownership of your deployments to be moved to your own Netlify account and then set any domain.