2

I follow this moleculer tutorial:

When I execute the 7th step:

7. We create docker-compose.yml and define our services in it: 
and run it up.

I get issue, I cannot start up the other three containers: enter image description here

the error info is below :

Service name can't be empty! Maybe it is not a valid Service schema. Maybe is it not a service schema? { schema: {} }
[2023-03-17T10:15:09.936Z] ERROR node-movies/BROKER: Failed to load service '/app/services/movies.service.js' { ServiceSchemaError: Service name can't be empty! Maybe it is not a valid Service schema. Maybe is it not a service schema?
    at Service.parseServiceSchema (/app/node_modules/moleculer/src/service.js:98:10)
    at new Service (/app/node_modules/moleculer/src/service.js:64:20)
    at ServiceBroker.createService (/app/node_modules/moleculer/src/service-broker.js:834:14)
    at ServiceBroker.loadService (/app/node_modules/moleculer/src/service-broker.js:799:16)
    at _.uniq.forEach.f (/app/node_modules/moleculer/src/runner.js:438:50)
    at Array.forEach (<anonymous>)
    at MoleculerRunner.loadServices (/app/node_modules/moleculer/src/runner.js:438:25)
    at MoleculerRunner.startBroker (/app/node_modules/moleculer/src/runner.js:510:8)
    at Promise.resolve.then.then.then.then (/app/node_modules/moleculer/src/runner.js:529:21)
    at process._tickCallback (internal/process/next_tick.js:68:7) code: 500, type: 'SERVICE_SCHEMA_ERROR', data: { schema: {} }, retryable: false }
[Runner] Service name can't be empty! Maybe it is not a valid Service schema. Maybe is it not a service schema? { ServiceSchemaError: Service name can't be empty! Maybe it is not a valid Service schema. Maybe is it not a service schema?
    at Service.parseServiceSchema (/app/node_modules/moleculer/src/service.js:98:10)
    at new Service (/app/node_modules/moleculer/src/service.js:64:20)
    at ServiceBroker.createService (/app/node_modules/moleculer/src/service-broker.js:834:14)
    at ServiceBroker.loadService (/app/node_modules/moleculer/src/service-broker.js:799:16)
    at _.uniq.forEach.f (/app/node_modules/moleculer/src/runner.js:438:50)
    at Array.forEach (<anonymous>)
    at MoleculerRunner.loadServices (/app/node_modules/moleculer/src/runner.js:438:25)
    at MoleculerRunner.startBroker (/app/node_modules/moleculer/src/runner.js:510:8)
    at Promise.resolve.then.then.then.then (/app/node_modules/moleculer/src/runner.js:529:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  code: 500,
  type: 'SERVICE_SCHEMA_ERROR',
  data: { schema: {} },
  retryable: false }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! moleculer-demo02@1.0.0 start: `moleculer-runner`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the moleculer-demo02@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-03-17T10_15_09_945Z-debug.log

and before step 7, I have filled the content of the servivces.

such as services/movies.service.js:

"use strict"; 

const movies = [
    {id: 1, title: 'Sharknado'},
    {id: 2, title: 'Roma'},
];

module.exports = {
    name: "movies",

    actions: {
        listAll(ctx) {
           return Promise.resolve({ movies: movies });
        },
        getById(ctx) {
            const id = Number(ctx.params.id);
            return Promise.resolve(movies.find(movie => movie.id === id ));
        },
        create(ctx) {
            const lastId = Math.max(...movies.map(movie => movie.id));
            const movie = {
                id: lastId + 1,
                ...ctx.params.payload,
            };
            movies.push(movie);
            this.broker.emit("movie.created", movie);
            return Promise.resolve(movie);
        }
    },
};

You see there has the service name:

module.exports = {
    name: "movies",

Edit-01

docker-compose.yml:

version: '3.7'
services:
  rabbitmq:
    image: rabbitmq:3.7-alpine
  gateway:
    build:
      context: .
    image: service-gateway
    env_file: .env
    environment:
      NODEID: "node-gateway"
      SERVICES: gateway
      PORT: 3000
    ports:
      - "3000:3000"
    depends_on:
      - rabbitmq
  email:
    build:
      context: .
    env_file: .env
    environment:
      NODEID: "node-email"
      SERVICES: email
    depends_on:
      - rabbitmq
  movies:
    build:
      context: .
    env_file: .env
    environment:
      NODEID: "node-movies"
      SERVICES: movies
    depends_on:
      - rabbitmq
qg_java_17137
  • 3,310
  • 10
  • 41
  • 84

1 Answers1

0

I may be missing the point of the tutorial , but i tried recreating the error that you were having , for that i just kept an empty object in each of the service and i was able to recreate the error.

Points I would like to add that would help you debug your error:

  1. In step 3 files are not created inside the services directory.
  2. By any chance did you tried building the image of Dockerfile before you added the code in its services. So on running docker-compose it points to old image of container which misses the required code.
  3. Try cleaning images of this project and try rebuilding it again.

Link to cleaning of old docker images. remove docker image

Haris Umaid
  • 106
  • 1
  • 8