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

js.Build unable to resolve file in data directory #11898

Closed
jmooring opened this issue Jan 17, 2024 · 4 comments
Closed

js.Build unable to resolve file in data directory #11898

jmooring opened this issue Jan 17, 2024 · 4 comments

Comments

@jmooring
Copy link
Member

jmooring commented Jan 17, 2024

The intended behavior may have changed at some point, but our documentation states:

Any imports in a file outside /assets or that does not resolve to a component inside /assets will be resolved by ESBuild with the project directory as the resolve directory (used as the starting point when looking for node_modules etc.)

assets/
├── js/
│   └── main.js
└── jsconfig.json
data/
└── data.json

assets/js/main.js

import data from "../../data/data.json";

There no directory mounts in site config (default mounts).

This stopped working in v0.78.1.

It may just be a documentation issue.

@bep bep added Upstream and removed NeedsTriage labels Jan 18, 2024
@bep bep added this to the v0.122.0 milestone Jan 18, 2024
@bep
Copy link
Member

bep commented Jan 18, 2024

So, the documentation is correct, I guess, but you need to look in ESBuild's documentation to see where that library looks for stuff. And my guess that's limited to what package.json says. If it worked before, it may be an upstream issue, but I would recommend to stick to either node_modules or assets.

@bep bep added NotSure and removed Upstream labels Jan 18, 2024
@bep
Copy link
Member

bep commented Jan 18, 2024

Looking at the diff, it indicates that this behaviour was probably changed by us in the above release.

image

But I don't remember it was ever intended for us to resolve anything in data etc, but this is 4 years ago.

@jmooring
Copy link
Member Author

jmooring commented Jan 18, 2024

Yeah, I ran across this while verifying that #7544 will be resolved by #11894, but I was unable to reproduce the setup due to this (11898) issue.

I'm going to close this, and will add a comment to 7544 to indicate the correct approach. The OP in 7544 wanted to access data.json from both JS (esBuild) and site.Data.data.foo, which should be handled with a mount.

[[module.mounts]]
source = 'assets'
target = 'assets'

[[module.mounts]]
source = 'data'
target = 'assets/data'

Then in main.js

import data from "data/data.json";
console.log(data.foo);

And with this setup, 7544 is definitely resolved with 11894.

Copy link

github-actions bot commented Feb 9, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants