fix: improve error message on incorrect service export (#6240)
**What** - Provide a more helpful error message if a user adds a file in `src/services` that doesn't export a service class. **Why** If you forget to `export default MyClass` in a custom service you can end up with this error:  It's almost impossible to know how to recover from this which can be an issue for new users. The new error message informs the user that there is a missing class export and shows which file the error is related to.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
fix(medusa): improve error message on incorrect service export
|
||||
@@ -469,6 +469,12 @@ export async function registerServices(
|
||||
const loaded = require(fn).default
|
||||
const name = formatRegistrationName(fn)
|
||||
|
||||
if (typeof loaded !== "function") {
|
||||
throw new Error(
|
||||
`Cannot register ${name}. Make sure to default export a service class in ${fn}`
|
||||
)
|
||||
}
|
||||
|
||||
const context = { container, pluginDetails, registrationName: name }
|
||||
|
||||
registerPaymentProcessorFromClass(loaded, context)
|
||||
|
||||
Reference in New Issue
Block a user