Home  >  Article  >  Backend Development  >  Unable to import... (No required module provides package '.../utils/...')

Unable to import... (No required module provides package '.../utils/...')

WBOY
WBOYforward
2024-02-12 17:15:12644browse

Unable to import... (No required module provides package .../utils/...)

Question content

Okay, I’m officially stumped. I looked at these 4 similar questions/answers:

No required module provides packet muxer error

Cannot import... (no required module provides package)

Cannot import local modules in golang

vscode: Unable to import golang package

...they all basically duplicate the same answer of running go mod init <name></name> and go mod tidy, which I've done numerous times, same problem still exists.

I did not upload this package to a github repository, it was just stored locally on my windows computer. I have run the command:

go mod init go_backtest

go mod tidy

...I still see these everywhere:

What’s interesting is that "go_backtest/strategies" There is no red underline under the line:

This is what the go.mod file looks like:

module go_backtest

go 1.19

I'm still new to golang, so please be kind, but how can I get this thing to "compile" and run (and make those red underlines disappear!)

Workaround

# The files in the ##utils directory should belong to the same package utils. These files should have the package utils line at the beginning.

And the import statement is used to import packages instead of files. So replace

"go_backtest/utils/datafuncs"
"go_backtest/utils/ga"

and

"go_backtest/utils"

The above is the detailed content of Unable to import... (No required module provides package '.../utils/...'). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete