medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
24.75k stars 2.44k forks source link

Cannot access backend #5039

Closed inmess closed 2 months ago

inmess commented 1 year ago

Bug report

Describe the bug

Before I met this problem, I added some entities and extended User, Product Entities. Not sure those changes are associated with this problem.

After I run medusa develop, I get:

❯ medusa develop
Successfully compiled 0 files with Babel (2ms).
[medusa-config] ⚠️ redis_url not found. A fake redis instance will be used.
[medusa-config] ⚠️ jwt_secret not found. fallback to either cookie_secret or default 'supersecret'.
[medusa-config] ⚠️ cookie_secret not found. fallback to either cookie_secret or default 'supersecret'.
info:    Using flag MEDUSA_FF_PRODUCT_CATEGORIES from project config with value true
info:    Using fake Redis
⠋ Initializing models
✔ Models initialized – 16ms
✔ Plugin models initialized – 34ms
✔ Strategies initialized – 14ms
⠋ Initializing modules
✔ Modules initialized – 2ms
✔ Database initialized – 43ms
✔ Repositories initialized – 10ms
⠋ Initializing services
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:7001/
<i> [webpack-dev-server] On Your Network (IPv4): http://192.168.1.194:7001/
<i> [webpack-dev-server] On Your Network (IPv6): http://[fe80::1]:7001/
<i> [webpack-dev-server] Content not from webpack is served from '/Users/xxxxx/Documents/xxxproject/public' directory
✔ Services initialized – 22ms
✔ Express intialized – 4ms
⠋ Initializing plugins
17:12:34 [@medusajs/admin] Running in development mode. Skipping setup.
error:   Error starting server
TypeError: Cannot read properties of undefined (reading 'prototype')
    at registerPaymentServiceFromClass (/Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/helpers/plugins.js:8:51)
    at /Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:375:87
    at step (/Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:33:23)
    at Object.next (/Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:14:53)
    at /Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:4:12)
    at /Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:366:87
    at Array.map (<anonymous>)
    at /Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:366:60
<i> [webpack-dev-middleware] wait until bundle finished: /login
assets by path *.js 36.7 MiB
  assets by chunk 13.6 MiB (id hint: vendors) 8 assets
  + 20 assets
assets by path *.ttf 1.24 MiB
  asset 442f6a4cc2f03aaf41f6.ttf 398 KiB [emitted] [immutable] [from: .cache/admin/src/fonts/Inter-SemiBold.ttf] (auxiliary name: main)
  asset 68fda0752a470b05a5c5.ttf 392 KiB [emitted] [immutable] [from: .cache/admin/src/fonts/Inter-Regular.ttf] (auxiliary name: main)
  + 3 assets
assets by path *.css 168 KiB
  asset main.css 142 KiB [emitted] (name: main)
  asset vendors-node_modules_react-datepicker_dist_react-datepicker_css-node_modules_react-nestable_d-9fafd9.css 25.7 KiB [emitted] (id hint: vendors)
  asset node_modules_moment_locale_sync_recursive_-_cache_admin_src_pages_a_tsx.css 907 bytes [emitted]
assets by path images/*.svg 2.33 KiB
  asset images/icon-plus-gray.svg 1.46 KiB [emitted] [from: node_modules/react-nestable/dist/styles/icon-plus-gray.svg] (auxiliary id hint: vendors)
  asset images/icon-minus-gray.svg 884 bytes [emitted] [from: node_modules/react-nestable/dist/styles/icon-minus-gray.svg] (auxiliary id hint: vendors)
asset index.html 437 bytes [emitted]
Entrypoint main 7.95 MiB (1.24 MiB) = runtime~main.bundle.js 14.9 KiB main.css 142 KiB main.bundle.js 7.8 MiB 5 auxiliary assets
orphan modules 369 KiB (javascript) 1.24 MiB (asset) 15.2 KiB (runtime) [orphan] 145 modules
runtime modules 83.9 KiB 49 modules
modules by path ./node_modules/ 6.97 MiB (javascript) 24.9 KiB (css/mini-extract)
  javascript modules 6.97 MiB 1599 modules
  css modules 24.9 KiB
    css ./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/dist/cjs.js!./node_modules/react-nestable/dist/styles/index.css 1.76 KiB [built] [code generated]
    css ./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/dist/cjs.js!./node_modules/react-datepicker/dist/react-datepicker.css 23.2 KiB [built] [code generated]
  ./node_modules/axios/package.json 1.92 KiB [built] [code generated]
modules by path ./.cache/admin/src/ 7.78 MiB (javascript) 142 KiB (css/mini-extract) 776 modules
./util.inspect (ignored) 15 bytes [built] [code generated]
webpack 5.88.2 compiled successfully in 6260 ms
<i> [webpack-dev-middleware] wait until bundle finished: /runtime~main.bundle.js
<i> [webpack-dev-middleware] wait until bundle finished: /main.css
<i> [webpack-dev-middleware] wait until bundle finished: /main.bundle.js
assets by status 1.41 MiB [cached] 10 assets
assets by path *.js 36.7 MiB
  assets by chunk 13.6 MiB (id hint: vendors)
    asset vendors-node_modules_react-datepicker_dist_react-datepicker_css-node_modules_react-nestable_d-9fafd9.chunk.js 8.84 MiB [emitted] [minimized] (id hint: vendors)
    asset vendors-node_modules_segment_analytics-next_dist_pkg_browser_index_js-node_modules_axios_inde-a66e1a.chunk.js 2.36 MiB [emitted] [minimized] (id hint: vendors)
    + 6 assets
  assets by chunk 7.8 MiB (name: main)
    asset main.bundle.js 7.8 MiB [emitted] [minimized] (name: main)
    asset main.fc5f1ef941af1d1356f0.hot-update.js 1.5 KiB [emitted] [immutable] [hmr] [minimized] (name: main)
  assets by chunk 15 KiB (name: runtime~main)
    asset runtime~main.bundle.js 14.9 KiB [emitted] [minimized] (name: runtime~main)
    asset runtime~main.fc5f1ef941af1d1356f0.hot-update.js 120 bytes [emitted] [immutable] [hmr] [minimized] (name: runtime~main)
  + 18 assets
asset index.html 437 bytes [emitted]
asset runtime_main.fc5f1ef941af1d1356f0.hot-update.json 43 bytes [emitted] [immutable] [hmr]
Entrypoint main 7.96 MiB (1.24 MiB) = runtime~main.bundle.js 14.9 KiB runtime~main.fc5f1ef941af1d1356f0.hot-update.js 120 bytes main.css 142 KiB main.bundle.js 7.8 MiB main.fc5f1ef941af1d1356f0.hot-update.js 1.5 KiB 5 auxiliary assets
cached modules 14.9 MiB (javascript) 167 KiB (css/mini-extract) 1.24 MiB (asset) 15.2 KiB (runtime) [cached] 2517 modules
runtime modules 38.4 KiB 21 modules
orphan modules 197 KiB [orphan] 1 module
./.cache/admin/src/assets/styles/global.css 335 bytes [built] [code generated]
webpack 5.88.2 compiled successfully in 1135 ms

And then I tried to access backend multiple times with http request and also admin dashboard, all failed with: net::ERR_CONNECTION_REFUSED

Meanwhile, the admin dashboard is reachable, just cannot login.

Here are some screenshots:

Admin dashboard console log

image

Postman http request result

image

However, all migrations are working as expected.

System information

Medusa version (including plugins): 1.15.0 Node.js version: 16.20.2 Database: Local Postgres Operating system: MacOS M2 Browser (if relevant): Safari / Chrome

Steps to reproduce the behavior

  1. Run command medusa develop

Expected behavior

Expect all http request working properly.

Code snippets

Here are some migrations that I executed, I hope it helps.

import { MigrationInterface, QueryRunner } from "typeorm";

export class ReviewPetReserveCreate1694342745147 implements MigrationInterface {
    name = 'ReviewPetReserveCreate1694342745147'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TABLE "reserve" ("id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "type" character varying NOT NULL, "pet_type" character varying NOT NULL, "pet_id" character varying NOT NULL, "start_date" TIMESTAMP NOT NULL, "days" integer NOT NULL DEFAULT '1', CONSTRAINT "PK_619d1e12dbedbe126620cac8240" PRIMARY KEY ("id"))`);
        await queryRunner.query(`CREATE TABLE "pet" ("id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP WITH TIME ZONE, "name" character varying NOT NULL, "type" character varying NOT NULL, "detailed_type" character varying, "date_of_birth" TIMESTAMP NOT NULL, "note" character varying, "weight" integer, CONSTRAINT "PK_b1ac2e88e89b9480e0c5b53fa60" PRIMARY KEY ("id"))`);
        await queryRunner.query(`CREATE TABLE "review" ("id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP WITH TIME ZONE, "anonymous" boolean NOT NULL, "content" text NOT NULL, CONSTRAINT "PK_2e4299a343a81574217255c00ca" PRIMARY KEY ("id"))`);
        await queryRunner.query(`ALTER TABLE "reserve" ADD CONSTRAINT "FK_df2e6e9f0f55ea9dd7e4a0db485" FOREIGN KEY ("pet_id") REFERENCES "pet"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "reserve" DROP CONSTRAINT "FK_df2e6e9f0f55ea9dd7e4a0db485"`);
        await queryRunner.query(`DROP TABLE "review"`);
        await queryRunner.query(`DROP TABLE "pet"`);
        await queryRunner.query(`DROP TABLE "reserve"`);
    }

}
import { 
    MigrationInterface, 
    QueryRunner,
    TableColumn, 
    TableForeignKey 
} from "typeorm"

export class CustomerExtend1694355329892 implements MigrationInterface {

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.addColumn(
            "review",
            new TableColumn({
                name: 'customer_id',
                type: 'varchar'
            })
        )
        await queryRunner.createForeignKey(
            "review",
            new TableForeignKey({
                columnNames: ['customer_id'],
                referencedColumnNames: ['id'],
                referencedTableName: 'customer'
            })
        )

        await queryRunner.addColumn(
            "pet",
            new TableColumn({
                name: 'customer_id',
                type: 'varchar'
            })
        )
        await queryRunner.createForeignKey(
            "pet",
            new TableForeignKey({
                columnNames: ['customer_id'],
                referencedColumnNames: ['id'],
                referencedTableName: 'customer'
            })
        )

        await queryRunner.addColumn(
            "reserve",
            new TableColumn({
                name: 'customer_id',
                type: 'varchar'
            })
        )
        await queryRunner.createForeignKey(
            "reserve",
            new TableForeignKey({
                columnNames: ['customer_id'],
                referencedColumnNames: ['id'],
                referencedTableName: 'customer'
            })
        )
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        const petTable = await queryRunner.getTable('pet')
        const petForeignKey = petTable.foreignKeys.find(
            fk => fk.columnNames.indexOf("customer_id") !== -1
        )
        await queryRunner.dropForeignKey("pet", petForeignKey)
        await queryRunner.dropColumn("pet", "customer_id")

        const reviewTable = await queryRunner.getTable('review')
        const reviewForeignKey = reviewTable.foreignKeys.find(
            fk => fk.columnNames.indexOf("customer_id") !== -1
        )
        await queryRunner.dropForeignKey("review", reviewForeignKey)
        await queryRunner.dropColumn("review", "customer_id")

        const resTable = await queryRunner.getTable('reserve')
        const resForeignKey = resTable.foreignKeys.find(
            fk => fk.columnNames.indexOf("customer_id") !== -1
        )
        await queryRunner.dropForeignKey("reserve", resForeignKey)
        await queryRunner.dropColumn("reserve", "customer_id")
    }

}
import { 
    MigrationInterface, 
    QueryRunner, 
    TableColumn, 
    TableForeignKey 
} from "typeorm"

export class ProductsExtend1694445660654 implements MigrationInterface {

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.addColumn(
            "review",
            new TableColumn({
                name: "product_id",
                type: "varchar"
            })
        )

        await queryRunner.createForeignKey(
            "review",
            new TableForeignKey({
                columnNames: ["product_id"],
                referencedColumnNames: ["id"],
                referencedTableName: "product"
            })
        )
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        const reviewTable = await queryRunner.getTable('review')
        const reviewForeignKey = reviewTable.foreignKeys.find(
            fk => fk.columnNames.indexOf("product_id") !== -1
        )
        await queryRunner.dropForeignKey("review", reviewForeignKey)
        await queryRunner.dropColumn("review", "product_id")
    }
}

In addition, a similar error occurred after I tried to add a new user with medusa user -e test@test.com -p testpassword:

[medusa-config] ⚠️ redis_url not found. A fake redis instance will be used.
[medusa-config] ⚠️ jwt_secret not found. fallback to either cookie_secret or default 'supersecret'.
[medusa-config] ⚠️ cookie_secret not found. fallback to either cookie_secret or default 'supersecret'.
info:    Using flag MEDUSA_FF_PRODUCT_CATEGORIES from project config with value true
info:    Using fake Redis
✔ Models initialized – 17ms
✔ Plugin models initialized – 32ms
✔ Strategies initialized – 17ms
⠋ Initializing modules
✔ Modules initialized – 3ms
✔ Database initialized – 42ms
✔ Repositories initialized – 17ms
✔ Services initialized – 38ms
✔ Express intialized – 3ms
⠙ Initializing plugins
TypeError: Cannot read properties of undefined (reading 'prototype')   // <-- This error is the same as given above
    at registerPaymentServiceFromClass (/Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/helpers/plugins.js:8:51)
    at /Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:375:87
    at step (/Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:33:23)
    at Object.next (/Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:14:53)
    at /Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:4:12)
    at /Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:366:87
    at Array.map (<anonymous>)
    at /Users/xxxxx/Documents/xxxproject/node_modules/@medusajs/medusa/dist/loaders/plugins.js:366:60

After all, it didn't add a new credential to the database...

This error seems like a plugin error? which is quite weird since I haven't do anything about plugin.

sradevski commented 2 months ago

Hey, thanks for the report! Since v2 brought a lot of architectural and API changes on the backend, we will be closing this ticket since it no longer applies to our new setup, or the issue has already been fixed. If you are still facing issues with v1, please open a new ticket and we will address it as soon as possible. Thanks! 🙏