medusajs / medusa

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

bug: migrations run yet app startup fails with error "Could not resolve module: orderOrderSalesChannelSalesChannelLink" (possibly related to specifying CA root cert) #7459

Open matmar10 opened 3 months ago

matmar10 commented 3 months ago

👋 Varme og venlige hilsner 🙂

Bug report

TL;DR: sslrootcert option ignored during module bootstrap phase; workaround is to specify sslmode=no-verify

Describe the bug

There is an issue with the module bootstrap phase of startup when connecting to a remote database:

It seems like (maybe) this is due to specifying self-signed and specifying CA root certificate (e.g. Digital Ocean).

Probably the way the modules are bootstrapped they are not passing all the connection string parameters to the underlying postgresql library?

Could not resolve module: orderOrderSalesChannelSalesChannelLink. Error: Loaders for module orderOrderSalesChannelSalesChannelLink failed: Unable to acquire a connection

Error initializing link modules. TypeError: Cannot set properties of undefined (setting '__definition')
    at MedusaModule.bootstrapLink (/home/username/projects/medusa-backend/node_modules/@medusajs/modules-sdk/dist/medusa-module.js:279:44)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async initialize (/home/username/projects/medusa-backend/node_modules/@medusajs/link-modules/dist/initialize/index.js:101:24)
    at async initializeLinks (/home/username/projects/medusa-backend/node_modules/@medusajs/modules-sdk/dist/medusa-app.js:99:32)
    at async MedusaApp_ (/home/username/projects/medusa-backend/node_modules/@medusajs/modules-sdk/dist/medusa-app.js:194:64)
    at async MedusaApp (/home/username/projects/medusa-backend/node_modules/@medusajs/modules-sdk/dist/medusa-app.js:243:16)
error:   Error starting server
GraphQLError: Syntax Error: Unexpected <EOF>.
    at syntaxError (/home/username/projects/medusa-backend/node_modules/graphql/error/syntaxError.js:15:10)
    at Parser.unexpected (/home/username/projects/medusa-backend/node_modules/graphql/language/parser.js:1458:41)
    at Parser.parseDefinition (/home/username/projects/medusa-backend/node_modules/graphql/language/parser.js:212:16)
    at Parser.many (/home/username/projects/medusa-backend/node_modules/graphql/language/parser.js:1511:26)
    at Parser.parseDocument (/home/username/projects/medusa-backend/node_modules/graphql/language/parser.js:122:25)
    at parse (/home/username/projects/medusa-backend/node_modules/graphql/language/parser.js:32:17)
    at cleanGraphQLSchema (/home/username/projects/medusa-backend/node_modules/@medusajs/modules-sdk/dist/utils/clean-graphql-schema.js:15:37)
    at cleanAndMergeSchema (/home/username/projects/medusa-backend/node_modules/@medusajs/modules-sdk/dist/medusa-app.js:115:80)
    at MedusaApp_ (/home/username/projects/medusa-backend/node_modules/@medusajs/modules-sdk/dist/medusa-app.js:201:34)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  path: undefined,
  locations: [ { line: 1, column: 1 } ],
  extensions: [Object: null prototype] {}
}

System information

Medusa version (including plugins):

Steps to reproduce the behavior

  1. Create a new project according to the getting started guide
  2. Modify the medusa config for Deploying on Digital Ocean
  3. Resolve the self-signed certificate issue described in discussion #4181 by adding &sslrootcert=./certs/db-pg-prod.crt to postgres DATABASE_URL

Expected behavior

Application should bootstrap successfully with valid DB credentials & certificate location.

I.E. if db migrations run successfully, then the application should also bootstrap successfully.

Screenshots

If applicable, add screenshots to help explain your problem

Code snippets

If applicable, add code samples to help explain your problem

Additional context

I have verified:

  1. Medusa bootstraps fine when connecting to local DB
  2. This is not related to database content. This issue persists even when the exact same data is in databases.
  3. DB connection IS valid. Have verified via CLI, and also Medusa.js migrations run fine on the remote Db.
jono-allen commented 3 months ago

I have got this aswell when setting up a new project. Using all latest versions of packages

matmar10 commented 3 months ago

@jono-allen Note you can use sslmode=no-verify in your connection string to ignore SSL verification.

Albeit insecure, it's a quick workaround until support for ca cert verification is supposed by the phase of the application lifecycle that loads the modules. Seems like the migration phase does it fine (since they will run okay).

riccardostokker commented 3 months ago

Hello, I am having exactly the same issue.

I have a medusa docker container deployed in my cluster. The database is being written, because i see the tables, and yet the application crashes as described here, with the same error.

After two days of debugging and coming across this issue, this was fixed by using ?sslmode=disable in the database connection string.

This was time consuming and doesn't seem like good practice. Is there something wrong with the installation? Does v2 have this issue?

Skwarek71830 commented 2 months ago

I'm having the same issue, but even locally and when running npx medusa migrations run, it started happening after I bumped my medusa version form 1.20.0 to 1.20.7, then I had rolled it and it still persists. Tried removing node_modules and clearing pnpm cache, no results

molhar commented 2 months ago

I had the same error after upgrading to 1.20.7 which I resolved by adding a resolution for modules-sdk to my monorepo root package.json:

"resolutions": {
    "@medusajs/modules-sdk": "^1.12.11"
  }

This also resolved another error I saw at the same time "GraphQLError: Syntax Error: Unexpected ."

Skwarek71830 commented 2 months ago

Solution for me (fixed the mentioned error, as well as "GraphQLError: Syntax Error: Unexpected .") and Module x not found in over 1400 places:

pavlotsyhanok commented 2 months ago

Same here!

wipermail commented 1 month ago

It started on Ubuntu without errors. With exactly the same setting, but on macos it throws an error. I've been trying to decide all day.

Slepzs commented 1 month ago

On macOs here, same issue. Haven't been able solve it yet.

I have tried:

wipermail commented 1 month ago

On macOs here, same issue. Haven't been able solve it yet.

I have tried:

  • Updating all packages to the same as starter template.
  • Disabling ssl using connection string
  • cleaned node modules.
  • Added @medusajs/modules-sdk to resolutions.
  • sslmode=no-verify is not working for me, it just creates a new issue.

I solved the error. In the problematic version I used pnpm. Switched to yarn and moved package-lock.json from the starting template repository.