Skip to content
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

Can't load admin panel in 4.12.4 on the public internet #17634

Closed
exchgr opened this issue Aug 9, 2023 · 57 comments · Fixed by #17645
Closed

Can't load admin panel in 4.12.4 on the public internet #17634

exchgr opened this issue Aug 9, 2023 · 57 comments · Fixed by #17645
Assignees
Labels
issue: bug Issue reporting a bug severity: high If it breaks the basic use of the product source: core:admin Source is core/admin package status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@exchgr
Copy link

exchgr commented Aug 9, 2023

Bug report

Required System information

  • Node.js version: v18.17.0
  • NPM version: 9.6.7
  • Strapi version: 4.12.4
  • Database: aurora postgres 14.6
  • Operating system: the docker container node:18-alpine, Linux 30339f198cc4 5.15.49-linuxkit-pr #1 SMP PREEMPT Thu May 25 07:27:39 UTC 2023 aarch64 Linux
  • Is your project Javascript or Typescript: typescript

Describe the bug

The Strapi admin panel won't load. It shows an error banner with the text:

Warning: An error occurred while requesting the API

Looking in the browser console, the browser also tries to make several requests to http://localhost:1337, which makes no sense on the public internet. I haven't changed any configurations between 4.12.1 and 4.12.4.

Steps to reproduce the behavior

  1. Visit a strapi admin panel deployed to an environment other than localhost

Expected behavior

The admin panel loads.

Screenshots

(hostname of my server redacted for privacy)
Screenshot 2023-08-09 at 6 09 02 PM

Code snippets

n/a

Additional context

I tried setting STRAPI_ADMIN_BACKEND_URL manually to the domain where my strapi server is, but it didn't work.

@exchgr exchgr changed the title Can't load admin panel in 4.12.4 Can't load admin panel in 4.12.4 on the public internet Aug 9, 2023
@exneval
Copy link

exneval commented Aug 10, 2023

Just want to confirm, I also have the same error after upgrade to 4.12.4 today, need to downgrade for now

@cannorin
Copy link

cannorin commented Aug 10, 2023

We've encountered the same issue by not upgrading strapi to v4.12.4 (it stays at v4.12.1), but rather upgrading @strapi/design-system to v1.9.0. Downgrading @strapi/design-system to v1.8.2 fixed the problem.

(We've also upgraded @strapi/icons to v1.9.0 and also downgraded it to v1.8.2, but I guess this shouldn't matter as it only provides icons...)

@Cretezy
Copy link

Cretezy commented Aug 10, 2023

Can also confirm, after upgrading to 4.12.4 from 4.12.1.

-        "@strapi/plugin-graphql": "^4.12.1",
-        "@strapi/plugin-i18n": "4.12.1",
-        "@strapi/plugin-users-permissions": "4.12.1",
-        "@strapi/strapi": "4.12.1",
+        "@strapi/plugin-graphql": "^4.12.4",
+        "@strapi/plugin-i18n": "4.12.4",
+        "@strapi/plugin-users-permissions": "4.12.4",
+        "@strapi/strapi": "4.12.4",

@gu-stav gu-stav self-assigned this Aug 10, 2023
@joshuaellis
Copy link
Member

joshuaellis commented Aug 10, 2023

I've just tried to create a new strapi-app with npx create-strapi-app@latest and did not run into this issue, i'll check the upgrade path now but can I confirm when you updated your strapi app you re-ran the build command to ensure the admin panel is rebuilt? :)

Edit: i've just created an app at 4.12.1 and then upgraded to 4.12.4 and still do not receive this error, can you please provide a reproduction?

@joshuaellis joshuaellis added issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around status: can not reproduce Not enough information to reproduce source: core:admin Source is core/admin package severity: high If it breaks the basic use of the product and removed severity: medium If it breaks the basic use of the product but can be worked around labels Aug 10, 2023
@github-actions
Copy link
Contributor

This is a templated message

Hello @exchgr,

Thank you for reporting this bug, however we are unable to reproduce the issue you described given the information we have on hand. Can you please create a fresh project that you are able to reproduce the issue in, provide clear steps to reproduce this issue, and either upload this fresh project to a new GitHub repo or compress it into a .zip and upload it on this issue?

We would greatly appreciate your assistance with this, by working in a fresh project it will cut out any possible variables that might be unrelated.
Please note that issues labeled with status: can not reproduce will be closed in 14 days if there is no activity.

Thank you!

@gu-stav
Copy link
Contributor

gu-stav commented Aug 10, 2023

I can confirm what ⬆️ @joshuaellis said. Could you please try and delete your node_modules directory and run yarn && yarn build && yarn develop again?

I was able to make STRAPI_ADMIN_BACKEND_URL work that way.

@cannorin
Copy link

cannorin commented Aug 10, 2023

@joshuaellis @exchgr sorry for wrong tagging! @gu-stav In our case, we always build a Docker image and push it to our server, which involves 1) yarn install and 2) yarn build.

Also, we don't set STRAPI_ADMIN_BACKEND_URL. We haven't encountered any problem on v4.12.1 and before.

@exneval

This comment was marked as spam.

@cannorin
Copy link

Yes, you would have to deploy it to somewhere to reproduce it.

@gu-stav
Copy link
Contributor

gu-stav commented Aug 10, 2023

I have tried running Strapi in Docker and mapped port 1339 to 1337, which is working well too:

Screenshot 2023-08-10 at 09 36 30
version: '3'
services:
  strapi:
    container_name: strapi
    build: .
    image: strapi:latest
    restart: unless-stopped
    env_file: .env
    environment:
      DATABASE_CLIENT: ${DATABASE_CLIENT}
      DATABASE_HOST: strapiDB
      DATABASE_NAME: ${DATABASE_NAME}
      DATABASE_USERNAME: ${DATABASE_USERNAME}
      DATABASE_PORT: ${DATABASE_PORT}
      JWT_SECRET: ${JWT_SECRET}
      ADMIN_JWT_SECRET: ${ADMIN_JWT_SECRET}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
      NODE_ENV: ${NODE_ENV}
    volumes:
      - ./config:/opt/app/config
      - ./src:/opt/app/src
      - ./package.json:/opt/package.json
      - ./yarn.lock:/opt/yarn.lock

      - ./.env:/opt/app/.env
      - ./public/uploads:/opt/app/public/uploads
    ports:
      - '1339:1337'
    networks:
      - strapi
    depends_on:
      - strapiDB

I think that should be sufficient to see the bug mentioned?

@exneval
Copy link

exneval commented Aug 10, 2023

@gu-stav can you try to self hosted the newest version somewhere? Local environment seems to be fine, no error related to Content Security Policy happened (refused to connect)

@joshuaellis
Copy link
Member

@exchgr, @exneval & @cannorin, can you please provide a reproduction? Without it we won't be able to debug the issue you're facing.

@exneval

This comment was marked as spam.

@gu-stav
Copy link
Contributor

gu-stav commented Aug 10, 2023

I have deployed a new Strapi app on Strapi cloud and it is all working fine:

Screenshot 2023-08-10 at 09 55 55

@exneval As Josh said: please make sure you deploy a clean Docker container, which does not cache node_modules and make sure you build the admin app beforehand.

We haven't done any major changes in this area and I can't recall any change that would break the overall behavior.

@exneval
Copy link

exneval commented Aug 10, 2023

@gu-stav

I'm using Production Dockerfile from the docs

@cannorin
Copy link

Will try to create a reproduction. Note that we're using a yarn cache (which is a separate thing than node_modules) but we always create node_modules from the ground up.

@exneval

This comment was marked as spam.

@exneval

This comment was marked as spam.

@gu-stav
Copy link
Contributor

gu-stav commented Aug 10, 2023

As Josh said: at this stage we need working reproduction (e.g. a Dockerfile) for a fresh 4.12.4 instance, to make sure there aren't any side-effects caused e.g. by a cached node_modules directory.

@exneval
Copy link

exneval commented Aug 10, 2023

As Josh said: at this stage we need working reproduction (e.g. a Dockerfile) for a fresh 4.12.4 instance, to make sure there aren't any side-effects caused e.g. by a cached node_modules directory.

Here it is

# Creating multi-stage build for production
FROM node:18-alpine as build
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev > /dev/null 2>&1
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /opt/
COPY package.json yarn.lock ./
RUN yarn config set network-timeout 600000 -g && yarn install --production
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY . .
RUN yarn build

# Creating final production image
FROM node:18-alpine
RUN apk add --no-cache vips-dev
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY --from=build /opt/node_modules ./node_modules
WORKDIR /opt/app
COPY --from=build /opt/app ./
ENV PATH /opt/node_modules/.bin:$PATH

RUN chown -R node:node /opt/app
USER node
EXPOSE 1337
CMD ["yarn", "start"]

@exneval
Copy link

exneval commented Aug 10, 2023

Another Hint when observing behavior 4.12.1 and 4.12.4 in a self hosted server

4.12.1: Trying to access /admin/project-type from my domain (200 OK request)

4.12.4: Trying to access /admin/project-type from localhost:1337 (blocking request)

@cannorin
Copy link

I've tried exposing a local Strapi instance to the internet with ngrok, but the issue did not reproduce. I have a feeling that this would need far more complex setup to reproduce. Will continue to investigate tomorrow or later.

@exchgr
Copy link
Author

exchgr commented Aug 10, 2023

Furthermore, I was able to reproduce this issue with a server running on localhost with these steps:

  1. yarn build
  2. yarn start
  3. ngrok http 1337
  4. open the ngrok url, with /admin on the end

@exneval
Copy link

exneval commented Aug 11, 2023

@matthewdenison thank you for the clue, that's answer my observation why strapi requesting to localhost for path /project-type

@cannorin
Copy link

cannorin commented Aug 11, 2023

I've also obtained a reproduction thanks to @exchgr and @matthewdenison.

  1. Run yarn create strapi-app to create a new Strapi project with TypeScript as the project language.

    • The Strapi version should be v4.12.4.
    • The issue does not reproduce if you set the project language to JavaScript.
  2. Run yarn build and then yarn develop to start Strapi locally.

    • I can confirm that not only yarn start but yarn develop also fails in this setup.
    • Here you would see the webpack error pointed out by @exchgr.
      image
  3. Use ngrok to expose it to the internet and open the admin panel through the domain assigned by ngrok.

    • As @exchgr says, you can achieve this by ngrok http 1337.
    • Here you would see the error originally reported by @exchgr.
      image

Hope this helps! @joshuaellis @gu-stav

@gu-stav
Copy link
Contributor

gu-stav commented Aug 11, 2023

Thank you for all of your clues and trying to find a reproduction 🙏🏼 - very helpful! I have informed the team that might have changed something around that and will keep you updated.

@gu-stav
Copy link
Contributor

gu-stav commented Aug 11, 2023

I believe we have found the issue 🚀. Could you do me a favor and check if the experimental release 0.0.0-experimental.05ba949586582197048cb6fb1506057918ec9033 fixes the issue for you?

Instead of version 4.12.4 you can use the version string ⬆️ in your package.json files. Please don't forget to delete .cache, build and start with a fresh node_modules 🤞🏼

@cannorin
Copy link

@gu-stav I can confirm that 0.0.0-experimental.05ba949586582197048cb6fb1506057918ec9033 does not cause the issue with the above steps of reproduction. Note that it was not necessary to clean .cache, build, and node_modules; it just worked by just replacing version strings and yarn && yarn build && yarn develop.

@gu-stav
Copy link
Contributor

gu-stav commented Aug 11, 2023

Wonderful. I'll leave the issue open till the next release (4.12.5, next Wednesday) to avoid duplicates and close it then.

@exneval
Copy link

exneval commented Aug 11, 2023

thank you all

@gu-stav gu-stav added status: confirmed Confirmed by a Strapi Team member or multiple community members and removed status: can not reproduce Not enough information to reproduce labels Aug 11, 2023
@strapi-bot
Copy link

This issue has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/strapi-4-0-desployed-admin-keep-call-to-http-localhost-1337-admin-project-type/15028/14

@thematrixdev
Copy link

@gu-stav I can confirm that 0.0.0-experimental.05ba949586582197048cb6fb1506057918ec9033 does not cause the issue with the above steps of reproduction. Note that it was not necessary to clean .cache, build, and node_modules; it just worked by just replacing version strings and yarn && yarn build && yarn develop.

Excuse me, what "version string" should be used instead of "4.12.4"?

@zvonimirr
Copy link

Still facing this on 4.12.5 with Node 20.5.1

@thematrixdev
Copy link

Still facing this on 4.12.5 with Node 20.5.1

I have not tried 4.12.5 yet. But do you use Strapi with Docker? Try remove all cache and build again. It might help.

@zvonimirr
Copy link

zvonimirr commented Aug 17, 2023

Hi @thematrixdev
I've managed to fix it in Docker:

RUN STRAPI_ADMIN_BACKEND_URL=$STRAPI_ADMIN_BACKEND_URL HOST=$STRAPI_ADMIN_BACKEND_URL yarn build
CMD ["yarn", "start"]

@cannorin
Copy link

I can confirm that 4.12.5 does not cause the issue with the steps of reproduction described in #17634 (comment).

@zvonimirr make sure @strapi/typescript-utils is also updated to 4.12.5. Setting STRAPI_ADMIN_BACKEND_URL should be unnecessary.

@zvonimirr
Copy link

@cannorin I couldn't create a new app as I was updating an already existing app

@cannorin
Copy link

@zvonimirr It shouldn't matter if you are creating a new app or updating an existing one. Try removing package-lock.json or yarn.lock, or try specifying the version in your package.json, I guess?

@thematrixdev
Copy link

Checked. The issue should have been fixed on v4.12.5.
image

I have been using yarn, but during debug I suspect it was due to yarn so I have replaced it with npm...
My dockerfile:

FROM node:18-alpine

RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev

ARG NODE_ENV
ENV NODE_ENV=${NODE_ENV}

ARG PUBLIC_URL
ENV PUBLIC_URL=${PUBLIC_URL}

ENV PATH /opt/node_modules/.bin:$PATH
EXPOSE 1337
CMD ["npm", "run", "develop"]

WORKDIR /opt/
COPY ./strapi/package.json ./strapi/package-lock.json ./
RUN npm config set fetch-retry-maxtimeout 600000 -g && npm install

WORKDIR /opt/app/
COPY ./strapi ./
RUN ["npm", "run", "build"]

@jnolascob
Copy link

I also have a problem with 4.12.4.

This issue disappeared after simply downgrading version to 4.12.1.

Thanks bro, that fixed the issue in my case.

@strapi-bot
Copy link

This issue has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/strapi-4-0-desployed-admin-keep-call-to-http-localhost-1337-admin-project-type/15028/16

@y-nk
Copy link

y-nk commented Dec 7, 2023

i'm having this bug now on 4.14.6 - all my files are TS, is it related?

@y-nk
Copy link

y-nk commented Dec 7, 2023

For the people coming here. I don't know why, and honestly i don't want to know. I had deleted src/admin/* files since i thought i didn't need them and it actually created this issue.

Bringing back those files (named src/admin/*.example.js) fixed it.

v4.14.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug severity: high If it breaks the basic use of the product source: core:admin Source is core/admin package status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
Status: Fixed/Shipped
Archived in project
Development

Successfully merging a pull request may close this issue.