question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image upload through AdminUI fails with server error: [Network error]: ServerParseError: Unexpected token < in JSON at position 0

See original GitHub issue

Bug report

Describe the bug

When I go to the AdminUI and click on CREATE in my Image list and then click on UPLOAD FILE and select a file, when I click on CREATE a second time (this time inside the little window that opened on the first ‘create’) to upload the image, the image upload fails.

To Reproduce

  1. Create an Image list using a LocalFileAdapter to upload the image
// index.ts
const staticPath = 'public';
const staticRoute = '';
const imageFileAdapter = new LocalFileAdapter({
	src: `${staticPath}/images`,
	path: `${staticRoute}/images`
})
// lists/Image.ts
import { File } from '@keystonejs/fields';
import log from '../util/log';

export default (keystone, { imageFileAdapter }) => {
	log(`file adapter for image ${imageFileAdapter}`);
	keystone.createList('Image', {
		schemaDoc: 'Image for Article',
		labelResolver: item => item?.file?.originalFilename ?? '',

		fields: {
			file: { type: File, adapter: imageFileAdapter }
		}
	});
};
  1. Add this Image list to Keystone app
  2. Boot app and go to AdminUI (AdminUI has AuthStrategy enabled)
  3. Go to Image list. Click on CREATE to create new Image. Select a file to upload and then click on CREATE a second time to upload it.

The following errors are traced to the console

error3

and the network info is

error2

Expected behaviour

The image should upload and be stored on the server and reflected in the AdminUI

Screenshots

upload-image

System information

  • OS: MacOS 10.14
  • Browser: Chrome, Firefox (latest)

Additional context

Image upload through the AdminUI worked for the first 6 weeks of our project, stopped working about two weeks ago (for reasons unknown, although the code was the same – change in keystone packages?), started working again last week after an upgrade of all packages, and since a new upgrade in the last two days to the very latest packages has stopped working again, but with different errors.

These are the package versions I have now:

  "@keystonejs/adapter-mongoose": "^8.0.1",
    "@keystonejs/app-admin-ui": "^5.9.5",
    "@keystonejs/app-graphql": "^5.1.5",
    "@keystonejs/app-next": "^5.1.2",
    "@keystonejs/app-static": "^5.1.2",
    "@keystonejs/auth-password": "^5.1.5",
    "@keystonejs/field-content": "^5.4.5",
    "@keystonejs/fields": "^9.0.0",
    "@keystonejs/fields-markdown": "^5.1.5",
    "@keystonejs/fields-wysiwyg-tinymce": "^5.2.3",
    "@keystonejs/file-adapters": "^6.0.1",
    "@keystonejs/keystone": "^8.0.0",
    "@keystonejs/list-plugins": "^5.1.4",
    "@keystonejs/oembed-adapters": "^5.1.3",

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ra-externalcommented, Jun 3, 2020

@MadeByMike Thanks – we solved this a while ago, I can’t remember what it was. I believe, again, updating the Keystone packages might have solved it.

1reaction
npinoncommented, May 7, 2020

If it can help I have solved the problem. It was because I was using an nginx reverse proxy. By check the logs I have found : 2020/05/07 12:34:39 [crit] 20447#0: *6 open() "/usr/local/var/run/nginx/client_body_temp/0000000001" failed (13: Permission denied)

Solved by giving the right permissions on this folder

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected token < in JSON at position 0 at new ApolloError ...
So your server probably returns an html document containing the 404 error message that starts with < from <html... . Apollo tries to...
Read more >
Why does the Catstronaut indicate "Error! Unexpected token ...
However, my screen shows the following message, “Error! Unexpected token < in JSON at position 0”, instead of the json response.
Read more >
Troubleshoot 'Uncaught SyntaxError: Unexpected token u in ...
The 'Uncaught SyntaxError: Unexpected token u in JSON at position 0' error is caused when the client has been asked to execute JSON.parse() ......
Read more >
Unexpected token < in JSON at position 0 - Dave Ceddia
The Cause. This happens when you make a request to the server and parse the response as JSON, but it's not JSON. The...
Read more >
Network error: Unexpected token < in JSON at position 0 - 8base
I'm working on a new starter app and have the following component in a react app that works perfectly using AppProvider. import React...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found