#Dagger JS Error

1 messages · Page 1 of 1 (latest)

lilac glade
#

Hi, I try to using Dagger with sample api express.

I try just this code :

import { dag, Container, Directory, object, func } from "@dagger.io/dagger"

@object()
class HelloDagger {
  @func()
  build(source: Directory): Container {
    return dag
      .container()
      .from("node:20")
      .withDirectory("/src", source)
      .withWorkdir("/src")
      .withExec(["npm", "install"])
      .withExec(["npm", "run", "start"])
      .withExposedPort(8088)
  }
}

Package.json of dagger :

{
  "type": "module",
  "dependencies": {
    "@dagger.io/dagger": "./sdk",
    "typescript": "^5.5.4"
  },
  "dagger": {
    "runtime": "node"
  },
  "packageManager": "npm@10.8.2"
}
#

I've this error :

*[main][~/Documents/devPerso/node-api-demo]$ dagger call build --source=.                                                           
✔ connect 0.2s
✔ loading module 8.5s
Caught panic:

runtime error: invalid memory address or nil pointer dereference

Restoring terminal...

goroutine 59 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:26 +0x5e
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:18 +0x13
github.com/charmbracelet/bubbletea.(*Program).recoverFromPanic(0xc0002c0000)
        /go/pkg/mod/github.com/charmbracelet/bubbletea@v1.1.1/tea.go:705 +0x8b
panic({0x1251980?, 0x202ff90?})
        /usr/local/go/src/runtime/panic.go:785 +0x132
main.(*moduleDef).loadTypeDefs(0xc000063200, {0x1625118, 0xc0009cccc0}, 0xc000209140)
        /app/cmd/dagger/module.go:895 +0x769
main.maybeInitializeModule({0x1625118, 0xc000544120}, 0xc000209140, {0x0, 0x0}, 0x0)
        /app/cmd/dagger/functions.go:365 +0xe77
main.initializeModule({0x1625118, 0xc000544120}, 0xc000209140)
        /app/cmd/dagger/functions.go:316 +0x45
main.(*FuncCommand).execute(0x20513a0, 0xc0003f9b08, {0xc0001321a0, 0x2, 0x2})
        /app/cmd/dagger/functions.go:271 +0x111
main.(*FuncCommand).Command.func2.1({0x1625118, 0xc000544120}, 0x0?)
        /app/cmd/dagger/functions.go:173 +0x1d2
main.(*FuncCommand).Command.func2.withEngine.2({0x1625150?, 0xc0000c2460?})
        /app/cmd/dagger/engine.go:62 +0x433
github.com/dagger/dagger/dagql/idtui.(*frontendPretty).spawn(...)
        /app/dagql/idtui/frontend_pretty.go:629
github.com/charmbracelet/bubbletea.(*Program).handleCommands.func1.1()
        /go/pkg/mod/github.com/charmbracelet/bubbletea@v1.1.1/tea.go:324 +0x7d
created by github.com/charmbracelet/bubbletea.(*Program).handleCommands.func1 in goroutine 56
        /go/pkg/mod/github.com/charmbracelet/bubbletea@v1.1.1/tea.go:318 +0x131

#

What is the problem ?

If I try a build.mjs with SDK Node his working :

import { connect } from "@dagger.io/dagger"

// initialize Dagger client
connect(
  async (client) => {
    // get reference to the local project
    const source = client.host().directory(".", { exclude: ["node_modules/"] })

    // get Node image
    const node = client.container().from("node:20").withExposedPort(8086)

    // mount cloned repository into Node image
    const runner = node
      .withDirectory("/src", source)
      .withWorkdir("/src")
      .withExec(["npm", "install"])
    // build application
    // write the build output to the host
    await runner
      .withExec(["npm", "run", "start"])
      .directory("/src")
      
  },
  { LogOutput: process.stderr },
)

Demo code :
https://github.com/Killian-Aidalinfo/node-api-demo

GitHub

Contribute to Killian-Aidalinfo/node-api-demo development by creating an account on GitHub.