#TypeError: loaded is not a function 1.17.3 getting this error after upgrade

23 messages · Page 1 of 1 (latest)

kindred plank
#

⠙ Initializing plugins
error: Error starting server
TypeError: loaded is not a function
at .../node_modules/@medusajs/medusa/dist/loaders/plugins.js:319:43
at Array.forEach (<anonymous>)
at registerCoreRouters (.../node_modules/@medusajs/medusa/dist/loaders/plugins.js:314:16)
at .../node_modules/@medusajs/medusa/dist/loaders/plugins.js:111:41
at step (.../node_modules/@medusajs/medusa/dist/loaders/plugins.js:33:23)
at Object.next (.../node_modules/@medusajs/medusa/dist/loaders/plugins.js:14:53)
at fulfilled (.../node_modules/@medusajs/medusa/dist/loaders/plugins.js:5:58)

radiant mortar
#

Have you updated all packages?

#

run npx npm-check-updates --target minor

radiant mortar
#

Oh damn

#

I'm having this too

kindred plank
#

all packages are updated, i think this related to a plugin which is not updated to this current version

turbid grotto
#

Do you have either a /store/route.ts or /admin/route.ts in your project? If that is the case then I think I know what the issue is and I'll jump on creating a fix asap

radiant mortar
#

@turbid grotto Yes, it starts to work after removing api routes

#

and no, it was /store/custom/route.js

#

Sorry, indeed there was still a /store/route.js in dist

kindred plank
#

I got /api/store/index.ts and /api/store/custom-route-handler.ts

turbid grotto
turbid grotto
radiant mortar
#

Yes, I saw that too.

kindred plank
#

import { Router } from "express";
import customRouteHandler from "./custom-route-handler";
import { wrapHandler } from "@medusajs/medusa";

// Initialize a custom router
const router = Router();

export function attachStoreRoutes(storeRouter: Router) {
// Attach our router to a custom path on the store router
storeRouter.use("/custom", router);

// Define a GET endpoint on the root route of our custom path
router.get("/", wrapHandler(customRouteHandler));
}

#

after removing the files + dist and cache then building again it worked

#

@turbid grotto is is it related to the problem you stated ?

turbid grotto
# kindred plank <@617657732673175562> is is it related to the problem you stated ?

Yes, the file needs to have a default export, otherwise this error will occur, as the code I linked above tries to call the default export, and if that doesn't exist then Medusa will crash.

Based on the code I am guessing you have the old API example routes but you have moved them outside of the /api/routes folder, and because of that the code I linked tries to load it and crashes.

kindred plank
#

perfect thank you for the help

radiant mortar
#

@turbid grotto My old custom epxress routes are not working now after deployment even tho I don't have anything in src/api/store

#

404

turbid grotto
# radiant mortar <@617657732673175562> My old custom epxress routes are not working now after dep...

Only when you deploy or also on local, and do you get any errors? You can have things in src/api/store, the current issue is just if you have a api/{store|admin}/{index|route}.ts with no default export.

You should be able to have a mix of both types of API routes with no issue. My best idea, without seeing your code, is that something is malformed somewhere in your /api folder. We unfortunately have try/catch around the registerApi function that mutes errors, as otherwise it would print an error for every single plugin that does not have custom endpoint with how the "old" endpoints are loaded. So it can be a bit difficult to debug it without adding a console.log manually in plugin loader in /node_modules/@medusajs/medusa. But id be happy to help you look at it, to see if there is some issue on our end.

radiant mortar
#

Yikes. Totally my fault. Thanks for the hint about something malformed in /src/api. I have removed my old stripe webhook endpoint file but didn't remove the import and route in src/api/index.js. I don't know why neither eslint nor babel did throw because of it, something is wrong with my config. It shouldn't even finish the build and deployment.
Sorry for the callout, I thought it's gonna be relevant for the upcoming fixes.