bun icon indicating copy to clipboard operation
bun copied to clipboard

Segmentation fault when calling `Bun.resolveSync` within `PluginBuilder.onResolve`

Open errilaz opened this issue 1 year ago • 0 comments

What version of Bun is running?

0.5.7

What platform is your computer?

Linux 5.15.0-58-generic x86_64 x86_64

What steps can reproduce the bug?

I am attempting to sidestep Bun's handling of .css imports. I run with bun -e *.css to do so. As the PluginBuilder.onLoad callback will give me the import specifier unresolved, I try to call onResolve and switch the extension to .js in order to use Bun.resolveSync without causing an infinite loop, then back to .css, so that onLoad then sees the true absolute path.

Bun.plugin({
  name: "css",
  async setup(builder) {
    const { readFileSync } = await import("fs")

    builder.onResolve({ filter: /\.css$/ }, ({ path, importer }) => {
      const absolute = Bun.resolveSync(path.replace(/\.css$/, ".js"), importer).replace(/\.js$/, ".css")
      return {
        path: absolute,
        namespace: "css",
      }
    })

    builder.onLoad({ filter: /\.css$/, namespace: "css" }, ({ path }) => {
      const css = readFileSync(path, "utf8")
      return {
        loader: "object",
        exports: { default: css },
      }
    })
  },
})

What is the expected behavior?

Bun.resolveSync returns an absolute path.

What do you see instead?

The call to Bun.resolveSync immediately causes:

1090991 Segmentation fault (core dumped)

Additional information

No response

errilaz avatar Feb 26 '23 13:02 errilaz