Strapi: Warning an error occurred while requesting the API

Viewed 5233

I've been struggling for hours trying to install Strapi on my Ubuntu server.

Ubuntu: 20.04
nodejs: v14.19.0
npm: 6.14.16
strapi: 4

npx create-strapi-app@latest my-project --quickinstall

All the installation process goes seamlessly but when I go to http://mydomain:1337/admin in order to create a first user I get this warning:

an error occurred while requesting the API.

I know this problem has been encountered several times but none of the suggested solutions have helped me so far. I also found this error in the Chrome console but I'm not not sure it's related to the my problem:

main.815f1087.js:2 Refused to connect to 'http://localhost:1337/admin/project-type' because it violates the following Content Security Policy directive: "connect-src 'self' https:".

Any idea ?

6 Answers

You need to build the app. Read this github issue

Run: npm run build or yarn build or strapi build depending on what you are using

Got the same problem, a simple restart of the server did it for me.

First Build your Application by using npm run build then run npm start.

First of all, need to Build the admin panel and then Start the application.

To build the admin panel,

npm run build
# or
yarn build

To start the application with auto-reload,

npm run develop
# or
yarn develop

when you change the port of your strapi app, you must run npm run build or yarn build or strapi build. because strapi admin templates use default port 1337 and for using on another port you must build the project again.

What I did is to change the host address from 0.0.0.0 to 127.0.0.1 in server.js and then ran npm run build and that fixed my issue. I know it sounds strange but it worked.

Thanks.

Related