# goesm: Go packages as native ES modules

> Plain JavaScript with TypeScript types. No WebAssembly, no glue code. Your bundler imports Go like any other module.

[Get started](https://goesm.dev/guide/getting-started.md) · [What is goesm?](https://goesm.dev/guide.md) · [GitHub](https://github.com/goesm-dev/goesm)

- **Go functions are JS functions**: No wasm instance, no wasm_exec.js, no marshalling. Calling an exported Go function costs what calling any JS function costs.
- **One ES module per package**: A tree of TypeScript modules with relative .ts imports. Vite, Rolldown, esbuild and Bun tree-shake, split and minify it, with source maps back to .go.
- [**Checked against native Go**](https://goesm.dev/reference/conformance.md): Every fixture runs under native Go and as ESM, and must agree. 898 of the 961 runnable tests of Go's own test suite pass.
- **Go stays Go**: go/packages and go/types are the frontend. go.mod, gopls, go vet and go test keep working on the same code.
- [**Vue and Astro**](https://goesm.dev/guide/vue.md): With gosfc, real Go runs in the <script setup lang="go"> of Vue components and in the ---go frontmatter of .astro files.
- [**Zero-code instrumentation**](https://goesm.dev/reference/otelc.md): goesm build -toolexec "otelc toolexec" emits the same OpenTelemetry spans a native build does.

## Write Go, import ESM

```go
package cart

type Item struct {
	Name     string
	Price    int
	Quantity int
}

func Total(items []Item) int {
	total := 0
	for _, item := range items {
		total += item.Price * item.Quantity
	}
	return total
}
```

```sh
go tool goesm emit-ts ./cart   # goesm-ts/example.com/app/cart.ts + the runtime
```

```ts
import { Item, Total, $runtime as rt } from "./goesm-ts/example.com/app/cart.ts";

Total(rt.sliceLit([new Item(rt.fromJSString("apple"), 120, 3)])); // 360
```
