Strapi: Warning an error occurred while requesting the API - node.js

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 ?

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

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

If you are running strapi CMS on docker, and using docker composer to build, then maintain the default port 1337 when binding the container port to your system port.
Do this: -1337:1337
Not this: -8000:13337

I had this error after upgrading to latest Strapi and all dependencies, what helped me, is to rebuild the Strapi admin interface:
yarn build
or
npm run build
then start develop
yarn develop
or
npm run develop

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

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

Npx fails on Azure App Service deployment

I'm trying to deploy a Node.js (Remix) application to an Azure App Service instance. After installing the npm packages, the post-install script must run for the Remix app to eventually work. The post-install script is npx remix setup node.
Unfortunately, the deployment fails because of the following reason:
npm ERR! could not determine executable to run
I get the same error when trying to use other npx commands, as npx prisma generate. I tried npm exec as well instead of npx.
Thank you in advance!
In startup command try using npx serve -s build/
Also, under your app service Settings blade check all the general settings.
Make sure that your web.config was published along with your app.

reactjs app not run after serve and start

I just installed node.js on my centos 7 server, then install react
it successfully created my new react app, after that, I run:
npm start
and or serve -s build
but none of these run in my browser.
This site can’t be reached
how can I solve this?
If you have sever inside can you try with start debugging of your application
Stop npm, if you're using yarn
Start the project with command above, inside your project home folder
yarn start
Take some time to learn commands below:

React: npm start - windows cannot find localhost

I am trying to follow tutorials for basic react-build-app.
ENVIRONMENT
I am using Ubuntu on Windows 10.
Node version: v13.3.0
NPM version: 6.13.1
So far I did,
npm install -g create-react-app
create-react-app calculator
cd calculator
npm start
PROBLEM
When I run npm start, I get pop up dialog from windows saying, Windows cannot find '\https://localhost:3000/\'. Make sure you typed the name correctly, and then try again.
Here is a screenshot of the error
However, in the cli, I see
Local: http://localhost:3000/
On Your Network: http://192.168.56.1:3000/
Note that the development build is not optimized.
To create a production build, use npm run build.```
But when I open my browser and go to http://localhost:3000/, I only see a blank page, and not the normal React logo.
EXPECTED OUTPUT
I should see the react logo when going to http://localhost:3000/, and not receive and error.
ATTEMPTS
Updated nodejs and npm.
Changed ports using package.json. Also tried
using .env file to change port. Same error.
Uninstalled and re-installed ubuntu 18.04 LTS and used NVM to install nodejs and npm.
WORKAROUND
I got tired of fixing error after error with linux, so I just set up npm and nodejs on windows instead. ran create-react-app on windows cli and it worked the first time. Told me something else was listening on the port i was trying to open, so prompted me to change port. I said yes. Now I get the landing page I was looking for.
I am very new at this and have been trying to figure this out for a couple days now, I would appreciate any advice. Thank you.
This is a WSL specific issue with one of the dependencies of react-scripts, more specifically open version 7.0.0.
To resolve, you can:
switch to react-scripts 3.2.0 in your package.json, or
run npm start from something else than WSL (e.g. Powershell), or
wait for open and react to fix the issue
Bug report in React Scripts:
https://github.com/facebook/create-react-app/issues/8081
And the corresponding bug report in open:
https://github.com/sindresorhus/open/issues/154
According to this post in the bug report in open the culprit is lines 76 & 77 of index.js in node_modules/open. If you comment them out then it works fine.
Link to comment:
https://github.com/sindresorhus/open/issues/154#issuecomment-562509596

Jhipster cannot open main page

I tried Jhipster today and created a new project following the tutorial.
But when I run mvnw command and visit localhost:8080
I got this:
But I have already enabled JavaScript in chrome browser.
Why do I still get this message?
Any advise? Thanks in advance.
This is the status of my project, please refer to the pic below:
Please go through the readme file and then follow the steps given there:
npm istall
npm install yarn --global
yarn start
I use this in the first time run...
Go to app folder and run:
yarn
mvnw
and some times.. only for livereload Angular, in another command line window.
Go to app folder and run:
run yarn start
While generating jHipster gateway one needs to install npm packages separately, if not done this kind of blank page will be thrown.
One can go to project gateway directory and simply hit command npm install this will take a some time to download all required npm packages into your gateway application. Once done run npm start within project directory, it will run the UI application on port 9000 by default, if not changed.
I did the below steps and it is working for me:
yarn install
yarn start or yarn webpack:build:main

Build Meteor in Docker cannot pass proxy setting

I use latest Nodejs image as base image to build meteor project. The docker is behind the corporate proxy.
I tried curl and npm install -g. Both of them can go through the proxy and download packages.
However, when I try to use meteor update, error prompts as:
Unable to update package catalog (are you offline?)
=> Errors while upgrading packages:
error: tunneling socket could not be established, cause=socket hang up
Then the next step is using run meteor build, and I sometimes also got the error as
error: tunneling socket could not be established,
cause=140434436118336:error:140770FC:SSL
routines:SSL23_GET_SERVER_HELLO:unknown
protocol:../deps/openssl/openssl/ssl/s23_clnt.c:795:
I test the proxy setting by echo it before I ran meteor command. It shown correctly.
Can anyone help? There is an bug fixes in meteor states that meteor can use http_proxy setting. https://github.com/meteor/meteor/commit/3177d9ad416ae97a98a2b8c4b2b40a9fc03f6b9c
I've actually found this to be an issue that occurs with docker across a couple of projects and solve it by simply restarting my docker machine (working on OSX)
$ docker-machine restart dev
Also Meteor doesn't support the more recent versions of node due in part to complexities associated with Fibers, you'll probably want to build your container FROM node:0.10.40

Resources