7 months ago
Hello,
I'm trying to deploy a simple nextjs project linked to a strapi without success.
I'm running into a major problem on the Railway side. The build fails because the JSON returned by Strapi cannot be parsed correctly, but this only happens on Railway…..
Output on Railway :
#12 42.36 Generating static pages (3/7)
#12 42.37 SyntaxError: Unexpected token / in JSON at position 0
#12 42.37 at JSON.parse (<anonymous>)
#12 42.37 at parseJSONFromBytes (node:internal/deps/undici/undici:5584:19)
#12 42.37 at successSteps (node:internal/deps/undici/undici:5555:27)
#12 42.37 at fullyReadBody (node:internal/deps/undici/undici:1665:9)
#12 42.37 at async specConsumeBody (node:internal/deps/undici/undici:5564:7)
#12 42.37 at async l (/app/.next/server/chunks/450.js:1:708)
#12 42.37 at async i (/app/.next/server/chunks/450.js:1:1009)
#12 42.37 at async d (/app/.next/server/app/about/page.js:1:35218)
#12 42.37 SyntaxError: Unexpected token / in JSON at position 0
#12 42.37 at JSON.parse (<anonymous>)
#12 42.37 at parseJSONFromBytes (node:internal/deps/undici/undici:5584:19)
#12 42.37 at successSteps (node:internal/deps/undici/undici:5555:27)
#12 42.37 at fullyReadBody (node:internal/deps/undici/undici:1665:9)
#12 42.37 at async specConsumeBody (node:internal/deps/undici/undici:5564:7)
#12 42.37 at async l (/app/.next/server/chunks/450.js:1:708)
#12 42.37 at async i (/app/.next/server/chunks/450.js:1:1009)
#12 42.37 at async d (/app/.next/server/app/about/page.js:1:35218)
#12 42.37 Error: Error while fetching Strapi on path /profile
#12 42.37 at l (/app/.next/server/chunks/450.js:1:755)
#12 42.37 at async i (/app/.next/server/chunks/450.js:1:1009)
#12 42.37 at async d (/app/.next/server/app/about/page.js:1:35218) {
#12 42.37 digest: '936108846'
#12 42.37 }
#12 42.37 Error: Error while fetching Strapi on path /profile
#12 42.37 at l (/app/.next/server/chunks/450.js:1:755)
#12 42.37 at async i (/app/.next/server/chunks/450.js:1:1009)
#12 42.37 at async d (/app/.next/server/app/about/page.js:1:35218) {
#12 42.37 digest: '936108846'
#12 42.37 }
#12 42.37 Error: Error while fetching Strapi on path /profile
#12 42.37 at l (/app/.next/server/chunks/450.js:1:755)
#12 42.37 at async i (/app/.next/server/chunks/450.js:1:1009)
#12 42.37 at async d (/app/.next/server/app/about/page.js:1:35218) {
#12 42.37 digest: '936108846'
#12 42.37 }
#12 42.40
#12 42.40 Error occurred prerendering page "/about". Read more: https://nextjs.org/docs/messages/prerender-error
I've tried deploying on a VPS, Vercel or even locally, and I don't get this error at all, even though I'm connected to the same strapi hosted by Railway.
Output on Vercel :
✓ Generating static pages (7/7)
Finalizing page optimization …
Collecting build traces …
Route (app) Size First Load JS
┌ ○ / 126 kB 285 kB
├ ○ /_not-found 873 B 88 kB
├ ○ /about 12.9 kB 168 kB
├ ○ /projects 1.6 kB 107 kB
└ ● /projects/[slug] 6.18 kB 150 kB
└ /projects/
First Load JS shared by all 87.2 kB
├ chunks/12b088b0-0f487e0588505aff.js 53.6 kB
├ chunks/937-aec625e3a9c6be6f.js 31.6 kB
└ other shared chunks (total) 1.96 kB
○ (Static) prerendered as static content
● (SSG) prerendered as static HTML (uses getStaticProps)
Traced Next.js server files in: 35.731ms
Created all serverless functions in: 89.631ms
Collected static files (public/, static/, .next/static): 12.903ms
Build Completed in /vercel/output [1m]
Deploying outputs…
Deployment completed
The function used to fetch data on Strapi :
try {
const mergedOptions = {
next: { revalidate: process.env.NODE_ENV === "development" ? 0 : 300 },
headers: {
"Content-Type": "application/json",
Accept: "application/json", // force json response
},
...options,
};
const queryString = qs.stringify(params);
const requestUrl = `${process.env.STRAPI_BASE_URL}${path}${queryString ? `?${queryString}` : ""}`;
const response = await fetch(requestUrl, mergedOptions);
const data = await response.json();
return data;
} catch (error) {
console.error(error);
throw new Error(`Error while fetching Strapi on path ${path}`);
}
What can I do? I was convinced to use Railway, but now I'm beginning to think that it would take me less time to go to the other company than to try desperately to stay with Railway.
> ⓘ Deployment information is only viewable by project members and Railway employees.
8 Replies
7 months ago
This would be caused by some missconfiguration on your side, I would recommend printing the response body and status code to help you debug this issue.
7 months ago
This would be caused by some missconfiguration on your side, I would recommend printing the response body and status code to help you debug this issue.
Thanks for your quick reply.
I have this in the response body
#12 34.58 Error while fetching Strapi: SyntaxError: Unexpected token '/', "/
#12 34.58 "... is not valid JSON
#12 34.58 at JSON.parse (<anonymous>)
#12 34.58 at parseJSONFromBytes (node:internal/deps/undici/undici:5477:19)
#12 34.58 at successSteps (node:internal/deps/undici/undici:5459:27)
#12 34.58 at fullyReadBody (node:internal/deps/undici/undici:4378:9)
#12 34.58 at async consumeBody (node:internal/deps/undici/undici:5468:7)
#12 34.58 at async l (/app/.next/server/chunks/450.js:1:746)
#12 34.58 at async o (/app/.next/server/app/page.js:384:73373)
#12 34.58 at async ej (/app/.next/server/app/page.js:6:386345)
#12 34.58 Response clone body: /
#12 34.58 HTTP/1.1 400 Bad Request
#12 34.58 Connection: close
#12 34.58
#12 34.58 HTTP/1.1 408 Request Timeout
#12 34.58 Connection: close
#12 34.58
#12 34.58 HTTP/1.1 431 Request Header Fields Too Large
#12 34.58 Connection: close
#12 34.58
#12 34.58 HTTP/1.1 413 Payload Too Large
#12 34.58 Connection: close
#12 34.58
#12 34.58 form-data; name="; filename----
#12 34.58 ��J����+�^*R#�A��*�����2�N�D�g)9r�/���2�`
#12 34.58 �����P��y���h���<#a�ʤ���G8�t�18��V�0�s�+k&�._�'��v��o>�[�|��]��>k����k/��)��K���\'���f��#D�q��'2*�m��W����
#12 34.58 �P�"�NO3l%�����~��J�6D0q��A?�Iui}�����\��ybr���B���Lv
#12 34.58 5�شz@��n�^�������P�c���!�
#12 34.58 n��/�|��R �)�=��K�\��
����ڜ�Έ,�Llyv�4�Ыˈ=1��+ٴ�yA܆��h��<�?�[���[���K0�%Zd�[�}C���3[������!ʽ@ ڴBD��k����@o@�p"�m�C9�~��3�)M��8��^Z-��Y/_��-ZW=~]��٠�ݮK���`�L�֗pG�%b�:#L���ߦ�|ɐ
#12 34.58 HT��Ou�l��U��tK���S�p�j�����`]�9�?1z$��b۔!��3ؚ�fC6�k͝����
#12 34.58 �h�W��
#12 34.58 �srR����$Q��[�~��ME(���M�Z��6�&�
+��������Zf(�ޏ��PS>�DW�?b�ƑZ� 7����9S�l��(}/�{�*a%;�2#�j �e���e�;Գ+3F��
#12 34.58 �1�)AF�Wa���i�|(
��ؓ:����T싰>x�p�:�s�Wv�߲��".ΦQx����ɗz6���լp�`&���CNQo�;��a4�GuZ��H�P�W�4�{���y����"��^��W�H��D4�dg�G
M7ɵڛ�UX�Y1�����T���K�,L�~��Rd(�2q�[7����@�!�|�ie�i W-Rk��\%��6��8C~~������s���|�~QE�:Y�%6Y9}^sr��"���!��?�Y�;#����(N���}���ҷ��*�n�{���q�#12 34.58 �D�`�ʰy��Zv'>�\{��7H ��q;z���|��>yZ����J��1�9H�T�R�5���et�I�7�zp1�ҍN~��n��Y��m�^x2ȇ����@&q+�H����Z����s����������� :Ju7�2�m��pq�S!��o�<�DJ�nu�Z���G{'>�M�4�f�B-�Ը��B b>[X��v$ό5�D�Z(хk�q�����њQ�B�����ƿ&VՐ�B�Y@�_r�'�Z6�e�1G��� �<-�Zp,�z��8S�2}߰�
#12 34.58 ��6��A������D�GB��M�=�����̻�.�v!}܄�w���!�9;k��\C*��c��ʚ�s�/
#12 34.58 ����1��M���f��,�5VO�_A\2z9}1�#A?B�Ș�܍�f�_
#12 34.58 ��b�t��Ĭx���(|�T�n�����2�l��c����$�fܬg�"���p�p>%�T���оE��h�q��{�-�Sd�0u��4�8��,��4�ٗ�(��-0�r�� �Z�U�I��v�i�~r�D�0H��?E�Rpgv��lz��W"W�9q�ER���;���.0�B A�B��N�]ͬ�F#������v�?2F��7�&BP��x��H���&�Ր�Y�P��N�n�Ϋ���!q�EWEGZY�>���#��JD��g��1���-={[�ę��`��_�Ԑ8=waz�OWm"��y<d�/��Z��X�'���[�y�$A�D�Ǚ�E�";A����vU<�vYfX:ޤ�n�$�h�-\�Xc8ֵĦ\��&�k*��3鱚�w�2��M�J"(zH$�ؗ�Z���_�29z>C��t;��-�h��BW%�htr��P�xZ�2�@赓.�o�D�b�W�Cq�H`z�ٲ�}�]�Vp4(��4�V~!�W��s;4bvksh
�&�w��sF+�X�X���O>izV�ͷ�g�,^�+`b3扳r�M�p��Qg��e���[���~�M���Ukh)�k
#12 34.58 ]U+t��̓JFuVC�j��8�5K"�Lb�^'��XzQr�gBc��)���:o'`k�YO�c���|��%��7���������?jv����,�T�C����6>G���K5��H��6�+��O�/��֕k,��e%:�I�D�br����O$Iv-.3��|���L��'ڕ�7y�2�?���!rK�G!%js>���9@�4��� ����b}����0�P���7'�ήâ2�5WqϤ�n0��f+�S�� =u�&Ó����q�0/�8(�F�_�s(���k1�4���R�����.E�U�!����L7��sW��᙮];YyOO��s9*��}'��mK�4�Ь�ba\Ⱥ�DGٽ$�8'�<�TC��[E��D���Gt́9���4��*��-` �p:�F��R�*i{ͯ�8ʡ�;,K� �Ѵ����qMk|�a<����Vk3�X��S�kQ�����F�݈�4�k�!5kÏ:���&ޚ_�u���R��fx"8T�Ui^)�.C�س�ؖu=W5�t7�:5,�L���x/-�����c�b�+��ad��ѡb ���ПKZȞ��oļ䈍���]!T ��B�]�9��`�R��%:D�u�'K��o�'..�.�`3�H���� �XǪ�9http/1.1{"data":[{"id":1,"type":"all","content":"Je donne vie à vos idées en créant des interfaces web intuitives et épurées qui reflètent votre vision.","createdAt":"2024-08-22T19:36:07.594Z","updatedAt":"2024-08-29T15:57:52.814Z","publishedAt":"2024-08-22T19:36:24.607Z","order":1,
7 months ago
#12 15.87 Request TEXT: /
#12 15.87 HTTP/1.1 400 Bad Request
#12 15.87 Connection: close
#12 15.87
#12 15.87 HTTP/1.1 408 Request Timeout
#12 15.87 Connection: close
#12 15.87
#12 15.87 HTTP/1.1 431 Request Header Fields Too Large
#12 15.87 Connection: close
#12 15.87
#12 15.87 HTTP/1.1 413 Payload Too Large
#12 15.87 Connection: close
#12 15.87
#12 15.87 form-data; name="; filename----
#12 15.87 ������pA�_�N�T��ˮu-5�&j��ߪ��)
#12 15.87 ���V!������8�B�-���rR~r%��ڻ���Cf15O�Lpǁ�i�nN"�-N���iW1��w�A
#12 15.87 �,��S��˖����p�����1;�s�g2oeP ��O��]/�g4G�1�S*���%'|�r���[u�~og��� m,A�r��=����=�c#�X�@�h't��N��{�q�!\�M|��W���V�hQ����p[��s�':P&�{&����ػa֝�J� *�����6({\����{���j�
I have this only on Railway, Vercel shows the data clearly, i don't know why
7 months ago
What do you expect ?
7 months ago
#12 15.87 Request TEXT: / #12 15.87 HTTP/1.1 400 Bad Request #12 15.87 Connection: close #12 15.87 #12 15.87 HTTP/1.1 408 Request Timeout #12 15.87 Connection: close #12 15.87 #12 15.87 HTTP/1.1 431 Request Header Fields Too Large #12 15.87 Connection: close #12 15.87 #12 15.87 HTTP/1.1 413 Payload Too Large #12 15.87 Connection: close #12 15.87 #12 15.87 form-data; name="; filename---- #12 15.87 ������pA�_�N�T��ˮu-5�&j��ߪ��) #12 15.87 ���V!������8�B�-���rR~r%��ڻ���Cf15O�Lpǁ�i�nN"�-N���iW1��w�A #12 15.87 �,��S��˖����p�����1;�s�g2oeP ��O��]/�g4G�1�S*���%'|�r���[u�~og��� m,A�r��=����=�c#�X�@�h't��N��{�q�!\�M|��W���V�hQ����p[��s�':P&�{&����ػa֝�J� *�����6({\����{���j�
I have this only on Railway, Vercel shows the data clearly, i don't know why
This is the data returned on the body of the response on Railway for a strapi request by next.js using fetch
7 months ago
We would need a minimal reproducible example that showcases this behaviour.
7 months ago
Hello,
Unfortunately I can't give you the source code on a public thread.
After a day's extensive research on this problem, it seems to be a “bug” or a specificity of Nixpacks.
The problem was the same locally when I created a docker image withNixpacks.
I then created a railway.toml
file at the root of the project as follows:
# railway.toml
[env]
NODE_ENV = “production
CI = “true
and a nixpacks.toml
file also at the project root:
providers = []
buildImage = 'ghcr.io/railwayapp/nixpacks:ubuntu-1707782610'
[variables]
CI = 'true'
NIXPACKS_METADATA = 'node'
NODE_ENV = 'production'
NPM_CONFIG_PRODUCTION = 'false'
[phases.build]
dependsOn = ['install']
cmds = ['pnpm run build'] # Use pnpm instead of yarn
cacheDirectories = [
'.next/cache',
'node_modules/.cache',
]
[phases.install]
dependsOn = ['setup']
cmds = ['pnpm install --frozen-lockfile'] # pnpm install
cacheDirectories = ['/usr/local/share/.cache/pnpm'] # Update cache for pnpm
paths = ['/app/node_modules/.bin']
[phases.setup]
nixPkgs = [
'nodejs_18',
'pnpm-9_x',
'openssl',
]
nixOverlays = ['https://github.com/railwayapp/nix-npm-overlay/archive/main.tar.gz']
nixpkgsArchive = 'bf744fe90419885eefced41b3e5ae442d732712d'
[start]
cmd = 'pnpm start' # Use pnpm to start
After that, using the New Builder Environment
on Railway, everything started working properly.
Maybe you'll be able to explain better the problem behind everything I've done, but I suspect I need to install openssl with nixPkgs to fix the problem.
Thank you, now everything works.