#[Solved] Object [class] not found in the module

1 messages · Page 1 of 1 (latest)

faint relic
#

I have created a private dagger module which has all the code related to build, test, etc.

In our UI repo, I added some dagger code to use that the above module.
My code:

export class Dagger {
  protected gzp: Gzp // Gzp is the name of exported module/Class
  protected source: Directory
  protected registry: string
  constructor(
    registryUser: string,
    registryToken: Secret,
    githubRunId: string,
    @argument({
      ignore: [
        "**/node_modules",
        ".dagger",
        "**/.next",
        "**/dist",
        "**/*.log",
        "**/.turbo",
        "**/*.md",
        ".github",
        ".git",
        ".vscode",
        "version.json",
      ],
    })
    source: Directory,
  ) {
    this.source = source
    this.registry = "hub.docker.com"

    this.gzp = dag.gzp(this.source, "ui", registryToken, "yarn", registryUser, {
      registry: this.registry,
      githubRunId: githubRunId,
    })
  }

  @func()
  build(): Promise<string> {
    return this.gzp.yarnBuild(".", {
      buildCommand: ["yarn", "build:next", "&&", "yarn", "build:server"],
      nodeImage: "node:18-alpine"
    }).export("build")
  }
}

When I run build. It throws the error: Object Gzp not found in the module

naive belfry
faint relic
#

The above code is from Dagger class which is present in the UI repo.
We have another repo which has a gzp class which I have installed in the above code.

So yeah, you are correct!
@naive belfry

faint relic
#

Also my gzp Module code:

@object()
export class Gzp {
    protected source: Directory;
// Some more fields ....
    constructor(
        @argument({
            ignore: [
                "**/node_modules",
                ".dagger",
        })
        source: Directory,
// Some more fields ....
    ) {
        this.source = source;
// Some more fields ....
    }

    private getNodeService(path: string, nodeImage = "node:20") {
        const nodeService = createNodeService(
            this.packageManager,
            {
                source: this.source,
                pipelineKey: this.name,
                nodeImage: nodeImage,
            },
        );
        return nodeService.setup(path);
    }

    @func()
    async yarnBuild(
        path: string,
        nodeImage = "node:20",
        buildCommand?: string[],
    ): Promise<Directory> {
        const service = this.getNodeService(path, nodeImage) as YarnNodeService;
        return service.build(path, buildCommand);
    }
}

If it helps. Or I might be writing the module in an incorrect way.

faint relic
#

My dagger module code was using constructor to init the exported object(gzp) and then use it in other methods. Like it's done in OOP. But when I read the code from other public modules. They are not doing it. Each either have a common init/setup functions which returns the native dagger type or yarn, pnpm, etc have their own setup/init.

What I was trying to do is to use a class which isn't natively supported by dagger. Hence the error.
Now I got this working with some refactoring.

Will this be supported in future or it's not possible or something else.

naive belfry
faint relic
#

Yeah, I had to refactor the code and change the implementations and calling method.
So it's sort of solved.

#

Will dagger support class based objects natively? Like it does for container, directory, secret, etc.

#

[Solved] Object [class] not found in the module

naive belfry
#

👍

naive belfry