-
Notifications
You must be signed in to change notification settings - Fork 91
SyntaxError: Unexpected token '<', " <h"... is not valid JSON #1892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey @Droppix, thanks for the report and sorry for the trouble. I'll look into it. |
Other remarks:
FYI: my nginx conf is:
|
JSON file does not seem to be a valid JSON file. I tried fixing it here: text.json. import { readFileSync } from "node:fs";
import { MeiliSearch } from "./dist/esm/index.js";
const client = new MeiliSearch({
host: "http://127.0.0.1:7700",
apiKey: "masterKey",
});
const INDEX_NAME = "index";
await client.deleteIndexIfExists(INDEX_NAME);
const index = client.index(INDEX_NAME);
const content = JSON.parse(readFileSync("./text.json"));
const enqueuedTask = await index.addDocuments([content]);
const task = await index.waitForTask(enqueuedTask.taskUid);
console.log(task);
const response = await index.getDocument(content.id);
console.log(response); So either #1741 fixed it or we just need a better reproduction. @Droppix Can you provide a reproducible example, please? |
The JSON file is valid, otherwise CURL would return an error and this is not the case. So, over the last few days, I've tried many tests, and I've noticed that whether it's curl or nodejs, the indexing goes well (no error), but only local network. However, as soon as you go through HTTPS (on nginx), it doesn't work on either CURL or node.js. And meilisearch display this log (on indexing curl or nodejs, on HTTPS):
Could you confirm my NGINX configuration with your team? I'm convinced that something is missing, certainly something to do with the size of the packet sent, especially since if you send a packet over 40KB in size, it's fine.
Thanks |
Well, I just tried parsing it and the following is what I get: import { readFileSync } from "node:fs";
import { MeiliSearch } from "meilisearch";
const client = new MeiliSearch({
host: "http://127.0.0.1:7700",
apiKey: "masterKey",
});
const INDEX_NAME = "index";
await client.deleteIndexIfExists(INDEX_NAME);
const index = client.index(INDEX_NAME);
const content = JSON.parse(readFileSync("./text.json"));
const enqueuedTask = await index.addDocuments([content]);
const task = await index.waitForTask(enqueuedTask.taskUid);
console.log(task);
const response = await index.getDocument(content.id);
console.log(response);
https://jsonlint.com/ is also returning an error for it. Maybe the file is different from what you're testing, or CURL is making adjustments to it somehow, I'm not sure. As to the NGINX config, I cannot provide that kind of support, nor can others here I'm pretty sure, maybe @Strift can chime in anyhow, though. |
Yeah, this one works. |
I'm coming back to you to see if you've been able to find a solution, as we're still stuck? Thanks |
I think this issue is clearly something related to your nginx config @Droppix can you try this config explained here: https://www.meilisearch.com/docs/guides/deployment/running_production#step-5-secure-and-finish-your-setup Then you can start adding the other configurations one by one until you see what is happening. I can't give you more help because the time is a constraint for me, but that will be my best recommendation. |
Description
I try to index only 1 document with 3 attributes (size of document => 41 KB)
I get an error: SyntaxError: Unexpected token '<', " <h"... is not valid JSON
Expected behavior
1/ If I send the command using curl, I have no errors
Request =>
curl -X PUT http://192.168.1.62:7700/indexes/cdfd3a26-d62a-484c-b78f-fb54805335e0/documents -H ‘Content-Type: application/json’ -H ‘Authorization: Bearer xxxxxxx’ --data-binary @text.json
Response =>
{‘taskUid’:88,‘indexUid’:‘cdfd3a26-d62a-484c-b78f-fb54805335e0’,‘status’:‘enqueued’,‘type’:‘documentAdditionOrUpdate’,‘enqueuedAt’:‘2025-03-12T14:47:31.554279Z’}
2/ If I send the same json with your npm package, and I call your method‘addDocuments([json]) or addDocuments(json)’, I get an exception :
SyntaxError: Unexpected token '<', "
<h"... is not valid JSON
text.json.zip
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: