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

Runtime require() gives "file not found" error even when file exists #14147

Open
jahooma opened this issue Sep 25, 2024 · 1 comment
Open

Runtime require() gives "file not found" error even when file exists #14147

jahooma opened this issue Sep 25, 2024 · 1 comment
Labels
bug Something isn't working napi Compatibility with the native layer of Node.js

Comments

@jahooma
Copy link

jahooma commented Sep 25, 2024

What version of Bun is running?

1.1.29+6d43b3662

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

I'm using workspaces. One workspace is called "test" and it imports code from the "common" workspace.

When I run bun test in the "test" workspace, it gives the following error for one of my test files:

error: ENOENT: No such file or directory
      at load (/Users/jahooma/manicode/node_modules/node-gyp-build/node-gyp-build.js:26:34)
      at /Users/jahooma/manicode/node_modules/tree-sitter/index.js:1:7

The "common" workspace uses the tree-sitter package, which uses the node-gyp-build package.

Bun has stored these packages at the root node_modules of my project.

In the line that errors, node-gyp-build is calling:

require("/Users/jahooma/manicode/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node")

This file totally exists on my machine, but throws an error. I don't think I'm doing anything special here.t

What is the expected behavior?

Require should load the file and not throw an error

What do you see instead?

> test git:(main) ✗ bun run test-manifold
$ bun test manifold-project.test.ts
bun test v1.1.29 (6d43b366)

__src__/manifold-project.test.ts:
Loading native module /Users/jahooma/manicode/node_modules/tree-sitter
Resolved path /Users/jahooma/manicode/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node
file exists true
file loads 406864

# Unhandled error between tests
-------------------------------
21 | function load (dir) {
22 |   console.log('Loading native module', dir)
23 |   console.log('Resolved path', load.resolve(dir))
24 |   console.log('file exists', fs.existsSync(load.resolve(dir)))
25 |   console.log('file loads', fs.readFileSync(load.resolve(dir)).length)
26 |   console.log('Runtime require', require(load.resolve(dir)))
                                      ^
error: ENOENT: No such file or directory
      at load (/Users/jahooma/manicode/node_modules/node-gyp-build/node-gyp-build.js:26:34)
      at /Users/jahooma/manicode/node_modules/tree-sitter/index.js:1:7
-------------------------------


 0 pass
 1 fail
 1 error
Ran 1 tests across 1 files. [242.00ms]
error: script "test-manifold" exited with code 1

Additional information

No response

@jahooma jahooma added bug Something isn't working needs triage labels Sep 25, 2024
@nektro nektro added napi Compatibility with the native layer of Node.js and removed needs triage labels Oct 10, 2024
@jahooma
Copy link
Author

jahooma commented Oct 18, 2024

I tried using tree-sitter outside a test and it linked me to the napi issue:
#158

Seems like this was the problem here. Would have been nice if it threw an appropriate error, because I spent a lot of time trying to figure out why it could not read that file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working napi Compatibility with the native layer of Node.js
Projects
None yet
Development

No branches or pull requests

2 participants