Skip to content

onLoad callback missing properties #27793

@pabloerhard

Description

@pabloerhard

What version of Bun is running?

1.3.10+30e609e08

What platform is your computer?

Darwin 25.2.0 arm64 arm

What steps can reproduce the bug?

Bun.plugin({
  name: 'plugin',
  setup (build) {
    build.onLoad({ filter: esmFilter, namespace: 'file' }, args => {
        console.log(`kind: ${args.kind}`)
        console.log(`namespace: ${args.namespace}`)
        console.log(`args: ${args}`)
        // Non altering code for demonstration purposes
       const content = readFileSync(filename, 'utf8')
       return { contents: rewritten, loader: 'js' }
    })
  },
})

What is the expected behavior?

According to the Bun documentation, the onLoad callback should receive an object containing the following properties:

path: the path to the matching module

importer: the module that imported this module

namespace: the namespace of the module

kind: the kind of import (e.g., entry-point, import-statement, dynamic-import, etc.)

Therefore, args.kind should not be undefined as well as any property other than path.

What do you see instead?

The above code prints:

kind: undefined
namespace: undefined
args: {
  path: somePath
}

Additional information

Also, the documentation never states that this plugin is intended for ESM code. Whenever CJS code enters the onLoad phase with loader set to 'js', it returns ESM code, which causes the application to break.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions