chapter-three / next-drupal

Next.js for Drupal has everything you need to build a next-generation front-end for your Drupal site: SSG, SSR, and ISR, Multi-site, Authentication, Webforms, Search API, I18n and Preview mode (works with JSON:API and GraphQL).
https://next-drupal.org
MIT License
638 stars 176 forks source link

Error: Internal server error #74

Open henlfern opened 2 years ago

henlfern commented 2 years ago

I'm trying to set up a local Drupal installation with this module. Everything works, but when it's time to launch the site, I receive this, and I can't get to wrap my head around it. Any idea what's wrong or what I can do to get the local server up and running?

Server Error Error: Internal Server Error This error happened while generating the page. Any console logs will be displayed in the terminal window.

Skärmavbild 2022-01-18 kl  19 05 54

Using XAMPP, Drupal 9.3.2.

shadcn commented 2 years ago

Anything in the Drupal logs? A server error is usually something went wrong on the Drupal side. Can you check the log and see? Does the site build yarn build?

henlfern commented 2 years ago

Quick answer, thank you.

The Drupal logs gave me enough information to find this issue: https://github.com/chapter-three/next-drupal/issues/15 in which I got the lead of "tokens". The Quick start guide doesn't go through the tokens, which is a bit sad, because that could have saved me some time debugging.

Looking for a way to get these tokens. I'm just a site-builder, and I haven't found an easy way to generate these tokens yet. If you have an easy guide of generating those, I'm happy to follow it.

shadcn commented 2 years ago

did you see the short video guide? https://next-drupal.org/learn/quick-start/create-role

Does this help?

I’ll work on improving the access tokens documentation.

henlfern commented 2 years ago

Yes, the videos are short and great, but the steps with tokens are missing. Perhaps that's a thing that an avid developer knows about, but for me, no. I don't know how to create tokens, and I didn't even know I needed them.

In context. I've been looking at NextJS for some time, but it was only when ChapterThree launched their Next-drupal.org-site that I thought it would be possible for me to start looking at it, all other guides were too long, too hard or similiar. And the steps are wonderful; short, to the point. And everything worked like a charm, until it was time to see the result. After that; extensive problem solving. So if information about tokens could be added, that would be super.

Anyway, thank you for everything, answers and the guide/site. I'm postponing my exploratory work for some days, need to attend other things, and I'll see if I'll give NextJS a new go.

// Adam

shadcn commented 2 years ago

I understand. Configuring access token takes some work/configuration right now.

Note that you don't need to manually create the tokens. You create a client/consumer and copy and paste the client id and secret into your .env file.

Which part specifically was a blocker for you? I want to improve the docs to make this easier.

Thanks for the feedback.

henlfern commented 2 years ago

It seems like you're describing keys. Am I wrong? I'm talking about tokens, the ones that should wind up on /admin/config/people/simple_oauth/oauth2_token After finding https://github.com/chapter-three/next-drupal/issues/15 I came to the conclusion that it's the tokens that are missing and that I lack the knowledge/guides how to generate them to make the stuff work.

Two things made the NextJS journey by ChapterThree troublesome for me. I mixed up secret, uuid and passwords, so my first attempt to set everything up didn't go so well. When I tried npm run dev I just got "Error: Specified images.domains should be an Array of strings received invalid values ()." That took some time to figure out that all the information in .env.local didn't add up. At recreating those steps I got to where I am now, with missing tokens to make the authentication work. The tokens are the second bump in the road for me.

Also, but that's not on you, I didn't have npm installed, so I had to look that up and install it.

shadcn commented 2 years ago

What development environment are you running Drupal on? Docker, ddev, Laravel Valet? I'll see if I can reproduce this issue.

henlfern commented 2 years ago

I'm running XAMPP 8.0.11-2 (which, I must confess I thought would be an obstacle when working with NextJS, but it turned out well).

besrabasant commented 2 years ago

I do face the same issue.

shadcn commented 2 years ago

@besrabasant Where are you blocked? With the access tokens?

besrabasant commented 2 years ago

Yes, How do I generate them?

Btw I get this error image

besrabasant commented 2 years ago

@shadcn Any probable solution for this issue?

shadcn commented 2 years ago

@besrabasant Can you try the following https://github.com/chapter-three/next-drupal/issues/15#issuecomment-899808977?

Are you on XAMPP as well?

besrabasant commented 2 years ago

I Already tried that but found no success. I am on laravel valet.

shadcn commented 2 years ago

I’m on Valet as well. Are you on https?

besrabasant commented 2 years ago

No.

shadcn commented 2 years ago

@besrabasant any thing in the drupal logs?

I'm running my site on Valet as well. Here's what I have:

  1. Drupal sites running at http://drupal.test.
  2. Next.js site at http://localhost:3000

with the following in my .env.local

NEXT_PUBLIC_BASE_URL=http://localhost:3000
NEXT_PUBLIC_DRUPAL_BASE_URL=http://drupal.test
NEXT_IMAGE_DOMAIN=drupal.test
DRUPAL_FRONT_PAGE=/home
DRUPAL_PREVIEW_SECRET=YEuHnbkd
DRUPAL_CLIENT_ID=f0174559-7b6a-43b3-9d62-05ba4956f271
DRUPAL_CLIENT_SECRET=4WHnh3AM7gee
besrabasant commented 2 years ago

Here are my env variables

NEXT_PUBLIC_DRUPAL_BASE_URL=http://drupal9.test
NEXT_IMAGE_DOMAIN=drupal9.test
DRUPAL_SITE_ID=drupal_next
DRUPAL_FRONT_PAGE=/home
DRUPAL_PREVIEW_SECRET=secret
DRUPAL_CLIENT_ID=1923f3de-fe47-455e-9871-4f803afaf9ce
DRUPAL_CLIENT_SECRET=password

here is my demo drupal installation https://github.com/besrabasant/druapl9

shadcn commented 2 years ago

@besrabasant I created a tool here to debug the connection. Can you try it and report back? See https://github.com/shadcn/next-drupal-debug

shadcn commented 2 years ago

@besrabasant any luck?

besrabasant commented 2 years ago

@shadcn I tested the connection with the tool and I see Connection Established successfully

image

solucionti commented 2 years ago

I get the same error here, clean install, I followed all the steps in the guide: https://next-drupal.org/learn/quick-start/install-drupal https://next-drupal.org/docs/quick-start

I checked the logs, and I didn't have any type of error. https://i.imgur.com/lxRywUl.gif

image

shadcn commented 2 years ago

@solucionti Looking into it. This is a fresh Drupal install?

solucionti commented 2 years ago

Hello, @shadcn , yes it is a clean installation

shadcn commented 2 years ago

@solucionti @besrabasant I'm pretty sure you've already done this but could you go through the following checklist and make sure everything is set up correctly? (I'm trying to reproduce the bug).

Thank you.

besrabasant commented 2 years ago

Yes @solucionti, I have performed all the configurations you have listed above

As also mentioned in the documentation.

solucionti commented 2 years ago

Ok @shadcn , today I will do a clean install. As soon as I have news I will send it to you.

solucionti commented 2 years ago

@shadcn I did a clean installation on two computers, on one it worked without problem, on the other at the time of installation using the command:

npx create-next-app -e https://github.com/chapter-three/next-drupal-basic-starter

I get the following warnign messages:

l v1.22.5 [1/4] Resolving packages... [2/4] Fetching packages... info @next/swc-android-arm64@12.0.10: The platform "linux" is incompatible with this module. info "@next/swc-android-arm64@12.0.10" is an optional dependency and failed compatibility check. Excluding it from installation. info @next/swc-android-arm64@12.0.10: The CPU architecture "x64" is incompatible with this module. info @next/swc-linux-arm-gnueabihf@12.0.10: The CPU architecture "x64" is incompatible with this module. info "@next/swc-linux-arm-gnueabihf@12.0.10" is an optional dependency and failed compatibility check. Excluding it from installation. info @next/swc-linux-arm64-gnu@12.0.10: The CPU architecture "x64" is incompatible with this module. info "@next/swc-linux-arm64-gnu@12.0.10" is an optional dependency and failed compatibility check. Excluding it from installation. info @next/swc-darwin-arm64@12.0.10: The platform "linux" is incompatible with this module. info "@next/swc-darwin-arm64@12.0.10" is an optional dependency and failed compatibility check. Excluding it from installation. info @next/swc-darwin-arm64@12.0.10: The CPU architecture "x64" is incompatible with this module. info @next/swc-darwin-x64@12.0.10: The platform "linux" is incompatible with this module. info "@next/swc-darwin-x64@12.0.10" is an optional dependency and failed compatibility check. Excluding it from installation. info @next/swc-win32-arm64-msvc@12.0.10: The platform "linux" is incompatible with this module. info "@next/swc-win32-arm64-msvc@12.0.10" is an optional dependency and failed compatibility check. Excluding it from installation. info @next/swc-win32-arm64-msvc@12.0.10: The CPU architecture "x64" is incompatible with this module. info @next/swc-win32-ia32-msvc@12.0.10: The platform "linux" is incompatible with this module. info "@next/swc-win32-ia32-msvc@12.0.10" is an optional dependency and failed compatibility check. Excluding it from installation. info @next/swc-win32-ia32-msvc@12.0.10: The CPU architecture "x64" is incompatible with this module. info @next/swc-linux-arm64-musl@12.0.10: The CPU architecture "x64" is incompatible with this module. info "@next/swc-linux-arm64-musl@12.0.10" is an optional dependency and failed compatibility check. Excluding it from installation. info @next/swc-win32-x64-msvc@12.0.10: The platform "linux" is incompatible with this module. info "@next/swc-win32-x64-msvc@12.0.10" is an optional dependency and failed compatibility check. Excluding it from installation. info fsevents@2.3.2: The platform "linux" is incompatible with this module. info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... [4/4] Building fresh packages... success Saved lockfile. Done in 9.16s. WindowsTerminal_GMRqGemIwi

solucionti commented 2 years ago

This is the error on the failing computer: chrome_1aLVHqtKxn

lauriii commented 2 years ago

I was running into similar problem when installing next-drupal on top of composer.json from Drupal Core and running PHP 8.0. The problem is caused by having PHP constraint on composer.json to require packages that support PHP 7.3.0, while running PHP 8.0 locally. The PHP 7.3.0 constraint in composer.json prevents composer from loading Simple OAuth 5.2.0 which is the version that makes the module compatible with PHP 8.0. Because Simple OAuth 5.2.0 isn't compatible with PHP 7.3.0 which is the version constraint in composer.json, composer loaded Simple OAuth 5.1.0 instead which isn't compatible with PHP 8.0.

The solution is to either downgrade PHP version to PHP 7.4, or remove the version constraint from composer.json:

@@ -45,9 +47,6 @@
     "config": {
         "preferred-install": "dist",
         "autoloader-suffix": "Drupal9",
-        "platform": {
-            "php": "7.3.0"
-        },
back-2-95 commented 2 years ago

@lauriii how can it be that we're on same issue within 30mins ??

Just got this thing working apart from Preview.

shadcn commented 2 years ago

Thanks for the update @lauriii I’ll add this to the docs.

@back-2-95 Let me know if you need help configuring preview.

back-2-95 commented 2 years ago

@shadcn I have just empty iframe, no errors on browser console or output in from npm run dev.

CleanShot 2022-02-15 at 12 32 34

back-2-95 commented 2 years ago

@shadcn It was Brave browser which blocked the preview iframe!

CleanShot 2022-02-15 at 13 17 15

henlfern commented 2 years ago

I did a new installation from scratch to see if that could make it work. I followed the guide, but ended up with the exact same error. The missing piece for me are the tokens, and I would really appreciate a guide on how I should create these tokens. // Adam

shadcn commented 2 years ago

@henlfern hmm and there's nothing in the Drupal logs? /admin/reports/dblog? Are you on PHP 7.4?

henlfern commented 2 years ago

@shadcn The only thing in the log is a notice that my public key should be 600 or 660 instead of 755 (and when I change it to 600 or 660 the notice changes to a warning stating "does not exist or is not readable", nice catch 22 there).

I'm on PHP 8.0.11.

The terminal (after running npm run dev) says:

error - Error: Unauthorized
    at /Applications/XAMPP/xamppfiles/htdocs/web/myblog/node_modules/next-drupal/dist/index.js:33:15
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async getStaticProps (webpack-internal:///./pages/index.tsx:84:17)
    at async Object.renderToHTML (/Applications/XAMPP/xamppfiles/htdocs/web/myblog/node_modules/next/dist/server/render.js:329:24)
    at async doRender (/Applications/XAMPP/xamppfiles/htdocs/web/myblog/node_modules/next/dist/server/next-server.js:1149:38)
    at async /Applications/XAMPP/xamppfiles/htdocs/web/myblog/node_modules/next/dist/server/next-server.js:1241:28
    at async /Applications/XAMPP/xamppfiles/htdocs/web/myblog/node_modules/next/dist/server/response-cache.js:64:36 

and then

wait  - compiling...
event - compiled successfully
shadcn commented 2 years ago

@henlfern it worked?

henlfern commented 2 years ago

No, not at all @shadcn I'm still convinced that it's the tokens that are the problem for my installation, but you never seem to listen to this. Every time I've brought it up you have avoided my questions and prays for a guide on how to add tokens to the installationen. 🤷‍♂️

shadcn commented 2 years ago

I understand. I saw compiled successfully and assumed it worked.

I've actually been looking into this and I added a solution for this in the latest next-drupal.

Initially we were providing a CLIENT_ID and a CLIENT_SECRET to next-drupal and it would use this to ask for a token from Drupal. In next-drupal 1.2.0, we can set a long-lived token instead of id and secret.

Let's try it out.

  1. On your Drupal site, visit /admin/config/people/simple_oauth.
  2. Under Access token expiration time, set a long time, say 2592000 (30 days).
  3. Next using Postman or Insomnia, make a POST request to your Drupal site to get a token.

next-drupal-token

  1. Copy the token and add it to your .env.local file under UNSTABLE_DRUPAL_ACCESS_TOKEN
UNSTABLE_DRUPAL_ACCESS_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJSU....
  1. Run yarn dev.

(Note: it's called UNSTABLE_DRUPAL_ACCESS_TOKEN because we're still testing this but this should unblock you for now)

If you're not familiar with Postman or Insomnia, happy to figure out another solution together.

fnick851 commented 2 years ago

I understand. I saw compiled successfully and assumed it worked.

I've actually been looking into this and I added a solution for this in the latest next-drupal.

Initially we were providing a CLIENT_ID and a CLIENT_SECRET to next-drupal and it would use this to ask for a token from Drupal. In next-drupal 1.2.0, we can set a long-lived token instead of id and secret.

Let's try it out.

  1. On your Drupal site, visit /admin/config/people/simple_oauth.
  2. Under Access token expiration time, set a long time, say 2592000 (30 days).
  3. Next using Postman or Insomnia, make a POST request to your Drupal site to get a token.

next-drupal-token

  1. Copy the token and add it to your .env.local file under UNSTABLE_DRUPAL_ACCESS_TOKEN
UNSTABLE_DRUPAL_ACCESS_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJSU....
  1. Run yarn dev.

(Note: it's called UNSTABLE_DRUPAL_ACCESS_TOKEN because we're still testing this but this should unblock you for now)

If you're not familiar with Postman or Insomnia, happy to figure out another solution together.

@shadcn Thanks, this worked for me. Do you think next-drupal is ready for production use?

shadcn commented 2 years ago

@fnick851 Yes it is. We shipped 1.0.0 a few months ago and we have been using it on several production sites.

theRuslan commented 2 years ago

Do you think next-drupal is ready for production use?

Yes, we also use it in production without any problems.

fnick851 commented 2 years ago

@shadcn I think the solution for this issue should be at least mentioned in the guide, especially for new comers.

Every time I start a next-drupal project and follow the guide, I encounter this exact issue on step https://next-drupal.org/learn/quick-start/create-nexts-project. I have a note for this issue so I'll just open this issue page and follow the steps you provided above to generate a UNSTABLE_DRUPAL_ACCESS_TOKEN. But many new users wouldn't know this.

So maybe just simply add a note in the guide and point them to this issue page?

Thanks.

fnick851 commented 2 years ago

@shadcn I believe some users (like me) are experiencing this issue because of on this page: https://next-drupal.org/learn/quick-start/create-consumer, under "Generate keys" section, there should be a step 5: Click Save.

Many users probably only clicked Generate and not Save which causes this issue later on.

shadcn commented 2 years ago

@fnick851 Ah nice catch. I'll update the docs. Thank you.