Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Could not resolve 'fileModuleService'. #7327

Open
kodermax opened this issue May 14, 2024 · 3 comments
Open

BUG: Could not resolve 'fileModuleService'. #7327

kodermax opened this issue May 14, 2024 · 3 comments

Comments

@kodermax
Copy link

I get an error with this config file
warn: Could not resolve module: FileModuleService. Error: 'super' keyword unexpected here

error: Error starting server
AwilixResolutionError: Could not resolve 'fileModuleService'.

const dotenv = require("dotenv");
const { Modules } = require("@medusajs/modules-sdk");

let ENV_FILE_NAME = "";
switch (process.env.NODE_ENV) {
  case "production":
    ENV_FILE_NAME = ".env.production";
    break;
  case "staging":
    ENV_FILE_NAME = ".env.staging";
    break;
  case "test":
    ENV_FILE_NAME = ".env.test";
    break;
  case "development":
  default:
    ENV_FILE_NAME = ".env";
    break;
}

try {
  dotenv.config({ path: process.cwd() + "/" + ENV_FILE_NAME });
} catch (e) {}

// CORS when consuming Medusa from admin
const ADMIN_CORS =
  process.env.ADMIN_CORS || "http://localhost:7000,http://localhost:7001";

// CORS to avoid issues when consuming Medusa from a client
const STORE_CORS = process.env.STORE_CORS || "http://localhost:8000";

const DATABASE_URL =
  process.env.DATABASE_URL || "postgres://localhost/medusa-starter-default";

const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379";

const plugins = [
  `medusa-fulfillment-manual`,
  `medusa-payment-manual`,

  {
    resolve: `medusa-plugin-meilisearch`,
    options: {
      // config object passed when creating an instance
      // of the MeiliSearch client
      config: {
        host: process.env.MEILISEARCH_HOST,
        apiKey: process.env.MEILISEARCH_API_KEY,
      },
      settings: {
        products: {
          indexSettings: {
            searchableAttributes: ["title", "description", "variant_sku"],
            displayedAttributes: [
              "id",
              "title",
              "description",
              "variant_sku",
              "thumbnail",
              "handle",
            ],
          },
          primaryKey: "id",
          transformer: (product) => ({
            id: product.id,
            title: product.title,
            description: product.description,
            variant_sku: product.variant_sku,
            thumbnail: product.thumbnail,
            handle: product.handle,
            // other attributes...
          }),
        },
      },
    },
  },
  // {
  //   resolve: `@medusajs/file-local`,
  //   options: {
  //     upload_dir: "uploads",
  //   },
  // },
  {
    resolve: "@medusajs/admin",
    /** @type {import('@medusajs/admin').PluginOptions} */
    options: {
      autoRebuild: true,
      develop: {
        open: process.env.OPEN_BROWSER !== "false",
      },
    },
  },
  {
    resolve: `medusa-plugin-resend`,
    options: {
      api_key: process.env.RESEND_API_ID,
      from: "info@casa-di-moda.ru",
      enable_endpoint: process.env.SES_ENABLE_ENDPOINT,
      template_path: "./data/templates",
      subject_template_type: "text",
      body_template_type: "react",
      order_placed_template: "order_placed",
      order_shipped_template: "order_shipped",
      customer_password_reset_template: "customer_password_reset",
      gift_card_created_template: "gift_card_created",
      //order_canceled_template: 'order_canceled',
      //order_refund_created_template: 'order_refund_created',
      //order_return_requested_template: 'order_return_requested',
      //order_items_returned_template: 'order_items_returned',
      //swap_created_template: 'swap_created',
      //swap_shipment_created_template: 'swap_shipment_created',
      //swap_received_template: 'swap_received',
      //claim_shipment_created_template: 'claim_shipment_created',
      user_password_reset_template: "user_password_reset",
      //medusa_restock_template: 'medusa_restock',
    },
  },
];

const modules = {
  eventBus: {
    resolve: "@medusajs/event-bus-redis",
    options: {
      redisUrl: REDIS_URL,
    },
  },
  cacheService: {
    resolve: "@medusajs/cache-redis",
    options: {
      redisUrl: REDIS_URL,
    },
  },
  [Modules.FILE]: {
    resolve: "@medusajs/file",
    options: {
      providers: [
        {
          resolve: "@medusajs/file-local-next",
          options: {
            config: {
              local: {},
            },
          },
        },
      ],
    },
  },
};

/** @type {import('@medusajs/medusa').ConfigModule["projectConfig"]} */
const projectConfig = {
  jwtSecret: process.env.JWT_SECRET,
  cookieSecret: process.env.COOKIE_SECRET,
  store_cors: STORE_CORS,
  database_url: DATABASE_URL,
  admin_cors: ADMIN_CORS,
  // Uncomment the following lines to enable REDIS
  redis_url: REDIS_URL,
};

/** @type {import('@medusajs/medusa').ConfigModule} */
module.exports = {
  projectConfig,
  plugins,
  modules,
  featureFlags: {
    product_categories: true,
  },
};

@adrien2p
Copy link
Member

do you have all the latest preview version installed?

@kodermax
Copy link
Author

kodermax commented May 18, 2024

which version do I need to install? my current package.json:

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "clean": "cross-env ./node_modules/.bin/rimraf dist",
    "build": "cross-env npm run clean && npm run build:server && npm run build:admin",
    "build:server": "cross-env npm run clean && tsc -p tsconfig.server.json",
    "build:admin": "cross-env medusa-admin build",
    "watch": "cross-env tsc --watch",
    "test": "cross-env jest",
    "seed": "cross-env medusa seed -f ./data/seed-ru.json",
    "start": "cross-env medusa start",
    "start:custom": "cross-env npm run build && node --preserve-symlinks --trace-warnings index.js",
    "dev": "cross-env npm run build:server && medusa develop"
  },
  "dependencies": {
    "@medusajs/admin": "7.1.14",
    "@medusajs/cache-inmemory": "latest",
    "@medusajs/cache-redis": "^1.9.1",
    "@medusajs/event-bus-local": "latest",
    "@medusajs/event-bus-redis": "^1.8.13",
    "@medusajs/file-local": "latest",
    "@medusajs/medusa": "^1.20.6",
    "@medusajs/pricing": "^0.1.12",
    "@medusajs/product": "^0.3.12",
    "@tanstack/react-query": "4.22.0",
    "body-parser": "1.20.2",
    "cors": "2.8.5",
    "dotenv": "16.4.5",
    "express": "4.17.3",
    "medusa-fulfillment-manual": "latest",
    "medusa-interfaces": "latest",
    "medusa-payment-manual": "latest",
    "medusa-payment-stripe": "latest",
    "medusa-plugin-meilisearch": "^2.0.10",
    "medusa-plugin-resend": "^1.1.0",
    "prism-react-renderer": "^2.0.4",
    "typeorm": "^0.3.20"
  },
  "devDependencies": {
    "@babel/cli": "^7.14.3",
    "@babel/core": "^7.14.3",
    "@babel/preset-typescript": "^7.21.4",
    "@medusajs/medusa-cli": "latest",
    "@stdlib/number-float64-base-normalize": "0.0.8",
    "@types/express": "^4.17.13",
    "@types/jest": "^27.4.0",
    "@types/mime": "1.3.5",
    "@types/node": "^17.0.8",
    "babel-preset-medusa-package": "^1.1.19",
    "cross-env": "^7.0.3",
    "eslint": "^6.8.0",
    "jest": "^27.3.1",
    "rimraf": "^3.0.2",
    "ts-jest": "^27.0.7",
    "ts-loader": "^9.2.6",
    "typescript": "^4.5.2"
  },
  "jest": {
    "globals": {
      "ts-jest": {
        "tsconfig": "tsconfig.spec.json"
      }
    },
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "testPathIgnorePatterns": [
      "/node_modules/",
      "<rootDir>/node_modules/"
    ],
    "rootDir": "src",
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$",
    "transform": {
      ".ts": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "./coverage",
    "testEnvironment": "node"
  }
}

@adrien2p
Copy link
Member

adrien2p commented May 18, 2024

To use medusa v2 you need to install the preview versions. Also, for now your plugins wont work as there is still some discussions/migrations to work on.
Also, it will be only to be able to tests the new architecture with the modules and new customization approaches etc as it is still a preview.
The versions are flagged with preview and the date in it such as 1.20.6-preview-20240518150544

Also, a new doc/book will be released alongside it. But for now you will be more in discovery mode if I can say.

Also, on a side note you haven't installed the file module or the file provider used in the module configuration

Cc @olivermrbl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants