Bug(?): Unexpected behavior in import-resolver with json files starting with '/' and mount config #2019
Unanswered
N8-B
asked this question in
Troubleshooting
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there!
In our app we've come across a potential bug in how
import-resolver
handles an import spec that starts with/
in combination with the user-provided mount configuration.Given the following config...
...and project structure:
The problem we're having is that the json imports that begin with
/
or/packages
are not handled correctly by theimportResolver
function - specifically this piece of code:https://github.com/snowpackjs/snowpack/blob/28be1890538e33447d651095ae8b9c390a0ecdc6/snowpack/src/build/import-resolver.ts#L52
With the above mount configuration the
getImportStats
function always returnsfalse
as the current logic to resolve the file location is calculating the path incorrectly.The problem as we understand it is as follows:
The resolution for absolute import specs uses:
path.resolve(root.config + spec without first slash)
. The final path is then used for a filesystem stat. The key here is that the file path is built from the import spec.However, the mount config is never used, which means that there are import specs that will fail the filesystem stat because the path will not exist in the fs.
An example given the mount config provided above:
As a result,
foo.json
is changed tofoo.json.js
and the wrapper function does not create the proxy file (foo.json.proxy.js
).Given this, we believe that, in the cases where the spec begins with
/
, the mount config should be used to build the final filesystem path.To get this working in our repo we have modified the logic to calculate the
importStats
for the given spec in the following section of code:https://github.com/snowpackjs/snowpack/blob/28be1890538e33447d651095ae8b9c390a0ecdc6/snowpack/src/build/import-resolver.ts#L51-L54
The current behavior is a blocking issue for our migration to snowpack. We have attempted a variety of different config options, but have yet to find something that works. Is there something that we have overlooked in our configuration?
We are using this patch now in our repo and everything is working great.
Here is a fork with our patch: main...N8-B:improve-json-import-spec-resolution
And a repo with the a working example: https://github.com/ferhtgoldaraz/snowpack-repro-json-and-mount-config
If you consider this is indeed a new 'feature' and open an issue, I can open a PR, with our changes and whatever test cases are required, where we can refine our solution with your input.
Let us know what you think!
Beta Was this translation helpful? Give feedback.
All reactions