HumanSignal / label-studio

Label Studio is a multi-type data labeling and annotation tool with standardized output format
https://labelstud.io
Apache License 2.0
19.56k stars 2.42k forks source link

yarn dev: Error: Must provide a proper URL as target at ProxyServer.<anonymous> #6567

Open lincolnneu opened 1 month ago

lincolnneu commented 1 month ago

Describe the bug In yarn dev mode, opening http://localhost:8010/ run into

Error: Must provide a proper URL as target
    at ProxyServer.<anonymous> (/label-studio/web/node_modules/http-proxy/lib/http-proxy/index.js:69:35)
    at HttpProxyMiddleware.middleware (/label-studio/web/node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:22:32)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

To Reproduce Steps to reproduce the behavior:

  1. Install for local development

Download latest dev branch. Following the READM.md in under web folder https://github.com/HumanSignal/label-studio/blob/0f5a47873a24080f74e3edf50cf3cbee96ef98a0/web/README.md#installation-instructions

yarn install --frozen-lockfile

create the .env (with the same content as .env.development From the web directory: Run yarn dev and wait till

webpack compiled successfully
  1. Go to http://localhost:8010
  2. The yarn session will show the error msg reported above, and the browser also shows the same error msg.

Expected behavior yarn dev should result in working frontend session, and http://localhost:8010 should show the label-studio UI

Environment (please complete the following information):

heidi-humansignal commented 1 month ago

Hello,

The error you're encountering indicates that the frontend development server's proxy configuration lacks a proper target URL. This usually happens when the backend server is not running or the proxy settings are incorrect. To resolve this issue, please follow these steps:

Step 1: Start the Backend Server

  1. Navigate to the root directory of Label Studio where manage.py is located.
  2. Start the backend server by running:

    python label_studio/manage.py runserver

By default, this will start the server at http://localhost:8080.

Step 2: Verify the Backend Server is Running

Step 3: Check Frontend Proxy Configuration

  1. In the web directory, ensure you have a .env file. If not, create one and copy the contents from .env.development.
  2. Open the .env file and verify that the VITE_BACKEND_HOST variable is set correctly:

    VITE_BACKEND_HOST=http://localhost:8080 Adjust the host and port if your backend server is running on a different address.

Thank you, Abu

Comment by Abubakar Saad Workflow Run

lincolnneu commented 1 month ago

Hello,

The error you're encountering indicates that the frontend development server's proxy configuration lacks a proper target URL. This usually happens when the backend server is not running or the proxy settings are incorrect. To resolve this issue, please follow these steps:

Step 1: Start the Backend Server

  1. Navigate to the root directory of Label Studio where manage.py is located.
  2. Start the backend server by running: python label_studio/manage.py runserver

By default, this will start the server at http://localhost:8080.

Step 2: Verify the Backend Server is Running

  • Open your browser and navigate to http://localhost:8080 to confirm that the backend server is running.

Step 3: Check Frontend Proxy Configuration

  1. In the web directory, ensure you have a .env file. If not, create one and copy the contents from .env.development.
  2. Open the .env file and verify that the VITE_BACKEND_HOST variable is set correctly: VITE_BACKEND_HOST=http://localhost:8080 Adjust the host and port if your backend server is running on a different address.

Thank you, Abu

Comment by Abubakar Saad Workflow Run

Hi, I followed your instruction and added VITE_BACKEND_HOST=http://localhost:8080 under /web/.env and still get the same errors.

I can confirm that the drango backend is running as the UI shows up when visiting http://localhost:8080. However, when visiting the frontend http://localhost:8010, it shows the error mentioned in this issue.

I also tried running the django backend and yarn dev from a mac, and get the same errors.

WangCheng0928 commented 3 weeks ago

so, how do you solve this? I have the same question~ thanks!

ArthurAlesi commented 3 weeks ago

having the same issue. even on windows or linux (wsl)

max82645235 commented 3 weeks ago

having the same issue in mac . Error: Must provide a proper URL as target

faleandroid commented 2 weeks ago

I'm having the same issue.

Buckler89 commented 1 week ago

Any update on this? I have the same problem

max82645235 commented 1 week ago

I solved the problem by updating the devServer.proxy option in the webpack.config.js file like this:

{ host: "127.0.0.1", // Port for the Webpack dev server port: HMR_PORT, // Enable HMR hot: true, // Allow cross-origin requests from Django headers: { "Access-Control-Allow-Origin": "*" }, static: { directory: path.resolve(__dirname, "../label_studio/core/static/"), publicPath: "/static", }, devMiddleware: { publicPath: ${FRONTEND_HOSTNAME}/react-app/, }, allowedHosts: "all", // Allow access from Django's server proxy: { '/api': { target: ${DJANGO_HOSTNAME}/api, changeOrigin: true, pathRewrite: { '^/api': '' }, secure: false, }, '/': { target: ${DJANGO_HOSTNAME}, changeOrigin: true, secure: false, } }, }

Buckler89 commented 1 week ago

thanks, it works!

heidi-humansignal commented 1 week ago

Please try out max82645235 solution and if there are still issues, please let us know. We will try to simplify this.

Thank you, Abu

Comment by Abubakar Saad Workflow Run

cnhgscc commented 3 days ago
          proxy: [
            // {
            //   router: {
            //     "/api": `${DJANGO_HOSTNAME}/api`, // Proxy api requests to Django's server
            //   },
            // },
            {
              context: ["/api"],
              target: `${DJANGO_HOSTNAME}`,
              secure: false,
              changeOrigin: true,
              logLevel: "debug",
            }
          ],