Skip to main content
Skip to main content

Common Create-React-App Errors

TypeError: cmd is not a function

This error typically occurs when you set up a Medusa project with create-medusa-app and try to run the Medusa backend.

To resolve this issue, make sure you change into the backend directory of the Medusa project you created before trying to start the Medusa backend:

cd backend
npx medusa develop

Admin Login or User Errors

By default, the Medusa backend runs on localhost:9000. However, the port may change based on the PORT environment variable.

If you run the create-medusa-app command, and the installation finishes successfully, but the backend runs on a different port than 9000, it may cause errors when you try to create an admin user or login during the onboarding process. This could either be because you have the PORT environment variable set to something differnt, or because of port forwarding.

To resolve this, you must:

  1. Terminate the create-medusa-app process and change to the new backend's directory.
  2. Either explicitely set the PORT environment variable to 9000, or set the environment variable MEDUSA_ADMIN_BACKEND_URL to the backend's URL. For example, if the backend is running on localhost:7000, change the MEDUSA_ADMIN_BACKEND_URL to http://localhost:7001. This ensures that the admin uses the correct port. In case of port fowarding, it's recommended to explicitely set the PORT environment variable.
  3. Create an admin user using the user command of the CLI tool.
  4. Start the backend again either with the dev command of the backend project or using npx medusa develop and try to login again.

Invalid Token Error with --no-browser Option

If you use the --no-browser option with the create-medusa-app command, you'll find a URL outputted at the end of the command execution. This is the URL that you can use to set a password for your admin user.

However, if you copy the URL, then try later to access that URL, you may receive an "Invalid Token" error. This is because when you copy the URL, a lot of extra space may be added into the token. So, you must clear out the spaces within the token and the || characters, then try again.

Alternatively, you can create a new user with the medusa user command.


Can't Connect to PostgreSQL Docker Container

When connecting your Medusa backend to a PostgreSQL Docker container, make sure the 5432 port is exposed.

To do that, either pass the -p option to the docker run command. For example:

docker run -d -p 5432:5432 --name some-postgres -e POSTGRES_PASSWORD=supersecret postgres

Or, if you're using Docker Desktop, you can provide the option under the container's "Optional settings" collapsable.

Setting Port option in Docker Desktop

If you expose the PostgreSQL docker container at a port other than 5432, make sure to include it in your database URL.

When installing Medusa with create-medusa-app, you can provide a database URL with the different port using the --db-url option.

For example:

npx create-medusa-app@latest --db-url "postgres://user:password@localhost:<YOUR_PORT>/medusa-store"

Where <YOUR_PORT> is the exposed port if it's different than 5432.

Refer to the database_url configuration documentation to learn how to set the database URL for an installed Medusa backend.


Can't connect to database with --db-url option

If you use the --db-url option with the create-medusa-app command and the connection to the database fails, try the following:

  • Specifying ?sslmode=require at the end of the connection URL. Some PostgreSQL hosting providers, like Vercel, require passing this option. For example:
npx create-medusa-app@latest --db-url "postgres://default:<password><host-region>.postgres.vercel-storage.com:5432/verceldb?sslmode=require"
  • Changing the password to remove special characters. PostgreSQL requires encoding passwords if they have special characters. While the create-medusa-app command handles this automatically when you specify the password to the create-medusa-app command, when you pass a connection URL with the --db-url the command uses that URL as-is. So, you must either encode the special characters in the password yourself, or remove the special characters in the password.

Other Errors

As a last resort to resolve your issue, please try to clear your npx cache, as it could hold a cached version of create-medusa-app with errors.

Run the following command:

rm -rf "$(npm config get cache)/_npx"

Try running the create-medusa-app command again.

If your issue persists, please try to search through our GitHub issues to see if there's a solution for your issue. If not, please create an issue on GitHub and our team will help you resolve it soon."

Was this section helpful?