I've been working on a cli tool in Go when I ran into this issue. The tool compiles and works perfectly fine when I use the Windows Command Prompt or PowerShell to run it but when I try using WSL (Ubuntu version 1) I get this error message.
time.Now().UnixMilli undefined (type time.Time has no field or method UnixMilli)
The file using time.Now().UnixMilli() has the package time included import(..."time"...) and it is not redefined elsewhere because the code compiles and runs correctly in the Windows terminals. Because of this I assume that it has something to do with Linux for Windows.
I have tried updating the $GOROOT and $GOPATH to various different places including trying to connect to go installed on the mounted Windows system /mnt/c/ (this gives a different error of not knowing how compile which makes sense since it's the Windows version of go). I have also tried uninstalling and reinstalling various versions of Go for Ubuntu using both apt-get and tar.
I'm not sure why it isn't working correctly and would love any insight that anyone else might have.
Thanks!
go env (windows-cmd):
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\<user>\AppData\Local\go-build
set GOENV=C:\Users\<user>\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\<user>\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\<user>\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.3
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\<user>\Documents\Firmware\Git\<project>\cli\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\<user>\AppData\Local\Temp\go-build2245089512=/tmp/go-build -gno-record-gcc-switches
go env (wsl-ubuntu):
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/<user>/.cache/go-build"
GOENV="/home/<user>/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/<user>/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.13/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/mnt/c/Users/<user>/Documents/Firmware/Git/<project>/cli/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build414455523=/tmp/go-build -gno-record-gcc-switches"