{"id":25649,"library":"goscript","title":"GoScript","description":"GoScript is an experimental Go-to-TypeScript transpiler that converts Go source code at the AST level into TypeScript, enabling sharing algorithms and business logic between Go backends and TypeScript frontends. Current stable version is 0.0.84 with frequent releases (weekly). Unlike GopherJS (full Go runtime in browser), GoScript aims for readable TypeScript output focused on self-contained algorithms. It supports structs, interfaces, generics, goroutines (mapped to async/await), channels, and limited stdlib. Uses JavaScript number type (64-bit float), no unsafe or complex numbers. Mature enough for sharing logic but not full Go apps.","status":"active","version":"0.0.84","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/aperturerobotics/goscript","tags":["javascript"],"install":[{"cmd":"npm install goscript","lang":"bash","label":"npm"},{"cmd":"yarn add goscript","lang":"bash","label":"yarn"},{"cmd":"pnpm add goscript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Generated code uses TypeScript features, requires TypeScript compiler for checking","package":"typescript","optional":true}],"imports":[{"note":"Package provides the compiler as a library; use the binary for CLI usage.","wrong":"const goscript = require('goscript')","symbol":"goscript (CLI)","correct":"import { goscript } from 'goscript'"},{"note":"Named export 'compile' is available for programmatic compilation.","wrong":"import * as goscript from 'goscript'; goscript.compile(...)","symbol":"compile","correct":"import { compile } from 'goscript'"},{"note":"TypeScript type for compile options, available since v0.0.80.","wrong":"","symbol":"GoscriptOptions","correct":"import { GoscriptOptions } from 'goscript'"}],"quickstart":{"code":"import { compile } from 'goscript';\nimport { writeFileSync, mkdirSync } from 'fs';\nimport { join } from 'path';\n\nconst goCode = `\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hello from GoScript!\")\n}\n`;\n\nconst result = compile({\n  files: { 'main.go': goCode },\n  packagePath: 'main',\n  outdir: './dist',\n});\n\nmkdirSync('./dist', { recursive: true });\nwriteFileSync(join('./dist', 'main.ts'), result.code, 'utf8');\nconsole.log('Compiled successfully!');","lang":"typescript","description":"Shows how to use the compile function to transpile a simple Go program to TypeScript programmatically."},"warnings":[{"fix":"Manually cast to BigInt in generated TypeScript if exact integer math is required.","message":"Go's int types (int, int64, uint32, etc.) are all translated to JavaScript's number type (64-bit float). Bitwise operations are truncated to 32 bits. Use BigInt if you need 64-bit integer precision.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Ensure your bundler or tsconfig resolves .ts imports correctly (e.g., moduleResolution: 'bundler').","message":"Since v0.0.81, generated imports use .ts extension (e.g., import './foo.ts' instead of './foo'). This may break projects that rely on module resolution without extension.","severity":"breaking","affected_versions":">=0.0.81"},{"fix":"Avoid using uintptr or unsafe.Pointer; refactor code to use slices or references instead.","message":"Pointer types are compiled to VarRef system; direct pointer arithmetic is not supported and will cause compilation errors.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Wrap async calls in an async IIFE or use top-level await if your target supports it.","message":"Goroutines and channels are translated to async/await. All functions that use channels become async, potentially requiring callers to await them. This can cause 'Top-level await' errors if not handled.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Pin to a specific version and expect to update imports when upgrading.","message":"The 'goscript' package is pre-v1.0 (v0.0.84). APIs may change without major version bump. There is no stable public API yet.","severity":"deprecated","affected_versions":"<1.0.0"},{"fix":"Check the list of supported packages in the documentation before compiling.","message":"Standard library support is incomplete. Many packages (e.g., net/http, os) are not fully implemented. Attempting to compile code using unsupported packages will fail.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Avoid relying on advanced reflection in code meant for compilation.","message":"Reflection is partially implemented. Some reflection features (like accessing unexported fields) may not work correctly.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"npm install goscript@latest","cause":"The 'goscript' package is not installed or not added to dependencies.","error":"Error: Cannot find module 'goscript'"},{"fix":"Use named import: import { compile } from 'goscript';","cause":"Importing the module incorrectly (e.g., default import instead of named import).","error":"TypeError: compile is not a function"},{"fix":"Change to ES module import or use dynamic import: import('goscript')","cause":"Using CommonJS require() with an ES module.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Remove or replace the unsupported package with a compatible alternative.","cause":"Attempting to compile a Go package that uses an unsupported standard library package.","error":"Error: Package 'fs' is not supported yet"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}