Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bun build fail to import implicit '.node' files when target is set to node #15550

Open
Fadoli opened this issue Dec 3, 2024 · 2 comments
Open
Labels
bug Something isn't working bundler Something to do with the bundler

Comments

@Fadoli
Copy link

Fadoli commented Dec 3, 2024

What version of Bun is running?

1.1.38+bf2f153f5

What platform is your computer?

Linux 6.11.5-amd64 x86_64 unknown

What steps can reproduce the bug?

Building with a target set to "node" with one of the JS file implicitly importing a .node addon, like for example krb5.

require('../build/Release/krb5');

What is the expected behavior?

When building for the bun target, the build is successfull.

The target node should behave the same way.

What do you see instead?

When building and targeting node the following error is emited :

❱ bun ./build.js  
140 |         format: 'cjs',
141 |         target: 'node',
142 |         external: []
143 |     }).then((output) => {
144 |         if (!output.success) {
145 |             throw new Error(`Failed backend bun build :\n${output.logs.join('\n')}`);
                        ^
error: Failed backend bun build :
ResolveMessage: Could not resolve: "../build/Release/krb5"

Additional information

No response

@Fadoli Fadoli added bug Something isn't working needs triage labels Dec 3, 2024
@heimskr
Copy link
Member

heimskr commented Dec 3, 2024

Would it be possible to provide your build.js file?

@Fadoli
Copy link
Author

Fadoli commented Dec 4, 2024

Yes but it's actually not required, the trigger is selecting node as a target.

Here is minimal files to reproduce the issue with the build file :

build.js :

const Bun = require('bun');

async function build() {
    await Bun.build({
        entrypoints: ['test.js'],
        outDir: './bun-build',
        format: 'cjs',
        target: 'node',
        external: []
    }).then((output) => {
        if (!output.success) {
            throw new Error(`Failed backend bun build :\n${output.logs.join('\n')}`);
        } else {
            console.log('Bun backend build successful');
        }
    });
}
build();

test.js :

const krb5 = require('krb5');

It happens when running bun build --target node ./test.js as well, with bun build --target bun ./test.js working as expected

@nektro nektro added bundler Something to do with the bundler and removed needs triage labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bundler Something to do with the bundler
Projects
None yet
Development

No branches or pull requests

3 participants