Skip to content

🐞 Error when dependency has same name as own module #6438

Closed

Description

@AnaisUrlichs

What is the issue?

I get the following error message when I try to install the Trivy integration:

❯ dagger mod install github.com/jpadams/daggerverse/trivy@21f9211e5727a0b6acce8a0ab6c35d01896dc642
✘ generatedCode ERROR [1.24s]
✘ exec /usr/local/bin/codegen --module . --propagate-logs=true --introspection-json-path /schema.json ERROR [0.64s]
┃ Error: generate code: template: module.go.tmpl:74:3: executing "_dagger.gen.go/module.go.tmpl" at <ModuleMainSrc>: error calling ModuleMainSrc: cann
┃  define methods on objects from outside this module                                                                                                
✘ generating go module: trivy ERROR [0.37s]
β”œ [0.22s] go mod tidy
┃ writing dagger.gen.go                                                                                                                              
┃ writing go.mod                                                                                                                                      
┃ writing go.sum                                                                                                                                      
┃ creating directory querybuilder                                                                                                                    
┃ writing querybuilder/marshal.go                                                                                                                    
┃ writing querybuilder/querybuilder.go                                                                                                                
┃ needs another pass...                                                                                                                              
β€’ Engine: 12d472085f11 (version v0.9.6)
β§— 2.90s βœ” 28 βˆ… 11 ✘ 3
Error: failed to automate vcs: failed to get vcs ignored paths: input:1: host.directory.asModule.generatedCode failed to get modified source directory for go module sdk codegen: process "/usr/local/bin/codegen --module . --propagate-logs=true --introspection-json-path /schema.json" did not complete successfully: exit code: 1

Here are the steps to reproduce:

  1. Clone the Github repositoryhttps://github.com/Cloud-Native-Security/dagger-trivy
  2. Run: dagger mod init --name=trivy --sdk=go
  3. Run: dagger mod install github.com/jpadams/daggerverse/trivy@21f9211e5727a0b6acce8a0ab6c35d01896dc642

Dagger version

dagger v0.9.6 (registry.dagger.io/engine) darwin/arm64

Steps to reproduce

Included above

It also relates to the following issue: #6329

the "quick" fix is to avoid running go mod init, because dagger mod init will take care of creating the go.mod file anyway if it doesn't exists, and it will have the "right" go version (the one used by the dagger container)
I tried this but it did not work

As you can see, my go.mod file does not have the minor version: https://github.com/Cloud-Native-Security/dagger-trivy/blob/4238c52dc1e0a66a10de7bbe1f97f8f963de83f1/app/go.mod#L3

Log output

Of the command?

Activity

  1. kpenfound commented on Jan 17, 2024

    @kpenfound
    Contributor

    This is an interesting one! It looks like the module you're trying to install, jpadams/daggerverse/trivy, is clashing with the name of your module, trivy. A workaround for now is to name your module in the mod init anything else

  2. sipsma commented on Jan 18, 2024

    @sipsma
    Contributor

    This is an interesting one! It looks like the module you're trying to install, jpadams/daggerverse/trivy, is clashing with the name of your module, trivy. A workaround for now is to name your module in the mod init anything else

    Yeah this is a tricky case, but not obscure enough to ignore since it's quite annoying to have to rename your own module like this. Due to the fact that transitive dependencies are hidden from dependers, this at least is only a problem when your own module name is the same as a direct dep.

    The fundamental problem is even though objects from dependency modules are namespaced, the "main module object" (and associated constructors) are not, so there will be graphql-level conflicts, in addition to possible SDK-specific naming conflicts depending on the SDK.

    I've figured for a while we may eventually want to add support for aliasing dependencies, conceptually similar to how most languages allow you to alias imports. That would allow this case to be supported I think. It's obviously not awesome that you'd have to go out of your way to do that (i.e. dagger mod install foobar --alias blahblah or something), but given this case of "module name is the same name as a direct dep" is likely not too common, I think I'd be okay with it.

  3. changed the title [-]🐞 Error: failed to automate vcs -- when trying to install different Dagger integrations[/-] [+]🐞 Error when dependency has same name as own module[/+] on Jan 23, 2024
  4. sipsma commented on Jan 31, 2024

    @sipsma
    Contributor

    The ability to rename dependencies was implemented in #6386

    Leaving this issue open since we still need to doc it :-)

  5. added
    kind/bug
    on Apr 20, 2024
  6. added and removed
    kind/bug
    on May 31, 2024
  7. added
    kind/bug
    on Jul 6, 2024
  8. locked and limited conversation to collaborators on Mar 24, 2026
  9. converted this issue into a discussion #12388 on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/sdkkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions