go

Import cycle not allowed


I have a problem with

import cycle not allowed

It appears when I am trying to test my controller. Here is the output:

can't load package: import cycle not allowed
package project/controllers/account
    imports project/controllers/base
    imports project/components/mux
    imports project/controllers/account
import cycle not allowed
package project/controllers/account
    imports project/controllers/base
    imports project/components/mux
    imports project/controllers/account
import cycle not allowed
package project/controllers/account
    imports project/controllers/base
    imports project/components/mux
    imports project/controllers/routes
    imports project/controllers/base

How do I read or understand this error? Where is the dependency wrong?


Solution

  • Here is an illustration of your first import cycle problem.

                      project/controllers/account
                         ^                    \    
                        /                      \
                       /                        \ 
                      /                         \/
             project/components/mux <--- project/controllers/base
                
                       
    

    As you can see with my bad ASCII chart, you are creating an import cycle when project/components/mux imports project/controllers/account. Since Go does not support circular dependencies you get the import cycle not allowed error during compile time.