adrien2p / medusa-plugins

A collection of awesome plugins for medusa :rocket:
https://medusa-plugins.vercel.app
MIT License
157 stars 46 forks source link

Medusa 1.18.1 - Undefined plugin #125

Closed iamanle closed 9 months ago

iamanle commented 10 months ago

Env:

Config setup: As usual for firebase

 {
    resolve: 'medusa-plugin-auth',
    options: {
      firebase: {
        credentialJsonPath: 'credentials/goloco-715d5-firebase-adminsdk-z7gkn-22da47ded5.json',
        admin: {
          // authPath: '/admin/auth/firebase',
          expiresIn: ONE_MONTH,
        },
        store: {
          // authPath: '/store/auth/firebase',
          expiresIn: ONE_MONTH,
          verifyCallback: async (container, decodedToken) => {
            const email = decodedToken.email;
            const firebaseId = decodedToken.uid;
            const manager = container.resolve('manager');
            const customerService = container.resolve('customerService');

Error: When yarn build:

➜ yarn build  
yarn run v1.22.19
warning package.json: "dependencies" has dependency "babel-preset-medusa-package" with range "^1.1.13" that collides with a dependency in "devDependencies" of the same name with version "^1.1.19"
$ cross-env npm run clean && npm run build:server && npm run build:admin

> medusa-starter-default@0.0.1 clean
> cross-env ./node_modules/.bin/rimraf dist

> medusa-starter-default@0.0.1 build:server
> cross-env npm run clean && tsc -p tsconfig.server.json

> medusa-starter-default@0.0.1 clean
> cross-env ./node_modules/.bin/rimraf dist

> medusa-starter-default@0.0.1 build:admin
> cross-env medusa-admin build

TypeError: Cannot read properties of undefined (reading 'plugins')
    at loadConfig (/Users/anle/Desktop/flip/flip-ticketing-v1/node_modules/@medusajs/admin/utils/load-config.js:8:31)
    at Command.<anonymous> (/Users/anle/Desktop/flip/flip-ticketing-v1/node_modules/@medusajs/admin/commands/build.js:50:49)
    at step (/Users/anle/Desktop/flip/flip-ticketing-v1/node_modules/@medusajs/admin/commands/build.js:33:23)
    at Object.next (/Users/anle/Desktop/flip/flip-ticketing-v1/node_modules/@medusajs/admin/commands/build.js:14:53)
    at /Users/anle/Desktop/flip/flip-ticketing-v1/node_modules/@medusajs/admin/commands/build.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/anle/Desktop/flip/flip-ticketing-v1/node_modules/@medusajs/admin/commands/build.js:4:12)
    at Command.build (/Users/anle/Desktop/flip/flip-ticketing-v1/node_modules/@medusajs/admin/commands/build.js:45:12)
    at Command.listener [as _actionHandler] (/Users/anle/Desktop/flip/flip-ticketing-v1/node_modules/commander/lib/command.js:482:17)
    at /Users/anle/Desktop/flip/flip-ticketing-v1/node_modules/commander/lib/command.js:1283:65
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
adrien2p commented 10 months ago

this does not seems to be an issue with the auth plugin no? looks like the issue comes from loading the medusa-config plugins.

gempain commented 5 months ago

I do have the same issue though. It's happening with the auth plugin only.

"medusa-plugin-auth": "^1.10.4",
"@medusajs/medusa": "1.20.2",

I get:

> cross-env ./node_modules/.bin/rimraf dist

> medusa-starter-default@0.0.1 build:admin
> cross-env medusa-admin build

TypeError: Cannot read properties of undefined (reading 'plugins')
    at loadConfig (/my-store/node_modules/@medusajs/admin/utils/load-config.js:8:31)
    at Command.<anonymous> (/my-store/node_modules/@medusajs/admin/commands/build.js:50:49)
    at step (/my-store/node_modules/@medusajs/admin/commands/build.js:33:23)
    at Object.next (/my-store/node_modules/@medusajs/admin/commands/build.js:14:53)
    at /my-store/node_modules/@medusajs/admin/commands/build.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/my-store/node_modules/@medusajs/admin/commands/build.js:4:12)
    at Command.build (/my-store/node_modules/@medusajs/admin/commands/build.js:45:12)
    at Command.listener [as _actionHandler] (/my-store/node_modules/commander/lib/command.js:482:17)
    at /my-store/node_modules/commander/lib/command.js:1283:65

@adrien2p you might want to reopen this IMO.

gempain commented 5 months ago

@adrien2p so I've done a bit of testing. The build fails when you set a value for options.store.callbackUrl.

The following config crashes:

{
      resolve: 'medusa-plugin-auth',
      /** @type {import('medusa-plugin-auth').AuthOptions} */
      options: [
        {
          type: 'auth0',
          strict: 'all',
          identifier: 'auth0',
          clientID: process.env.AUTH0_CLIENT_ID,
          clientSecret: process.env.AUTH0_CLIENT_SECRET,
          auth0Domain: process.env.AUTH0_DOMAIN,
          admin: {
            callbackUrl: `${ADMIN_URL}/admin/auth/auth0/cb`,
            failureRedirect: `${ADMIN_URL}/login`,
            successRedirect: `${ADMIN_URL}/`,
          },
          store: {
            callbackUrl: `${BACKEND_URL}/store/auth/auth0/cb`,
            failureRedirect: `${STORE_URL}/login`,
            successRedirect: `${STORE_URL}/`,
          },
        },
      ],
    },

while this one doesn't:

{
      resolve: 'medusa-plugin-auth',
      /** @type {import('medusa-plugin-auth').AuthOptions} */
      options: [
        {
          type: 'auth0',
          strict: 'all',
          identifier: 'auth0',
          clientID: process.env.AUTH0_CLIENT_ID,
          clientSecret: process.env.AUTH0_CLIENT_SECRET,
          auth0Domain: process.env.AUTH0_DOMAIN,
          admin: {
            callbackUrl: `${ADMIN_URL}/admin/auth/auth0/cb`,
            failureRedirect: `${ADMIN_URL}/login`,
            successRedirect: `${ADMIN_URL}/`,
          },
          store: {
            // callbackUrl: `${BACKEND_URL}/store/auth/auth0/cb`,
            failureRedirect: `${STORE_URL}/login`,
            successRedirect: `${STORE_URL}/`,
          },
        },
      ],
    },
gempain commented 5 months ago

Alright, so, I added some logging in /my-store/node_modules/@medusajs/admin/utils/load-config.js and interesting find right there which explains everything:

var configModule = (0, medusa_core_utils_1.getConfigFile)(process.cwd(), "medusa-config").configModule;
console.log('configModule', (0, medusa_core_utils_1.getConfigFile)(process.cwd(), "medusa-config"));

Gives me this log:

> medusa-starter-default@0.0.1 build:admin
> cross-env medusa-admin build

configModule {
  configModule: undefined,
  configFilePath: '/my-store/medusa-config.js',
  error: ReferenceError: BACKEND_URL is not defined
      at Object.<anonymous> (/my-store/medusa-config.js:63:29)

I guess: