You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running the fable compiler, jsNative functions with the Import attribute will change relative import paths if the output folder does not have the same depth as the fable project folder. I have this repo as an example: https://github.com/leononame/fable-repro
When using relative import Fable rewrite the imports so they always point to the same file depending on where you output the files. This is because Fable doesn't move JavaScript files so it adapt the relative imports to point to the original JavaScript position. Without that, you would need to move the JavaScript to the correct destination manually.
If you have the following structure where Program.fs use [<Import("log", "./util.js")>]
|- src
|- Program.fs
|- util.js
Then Fable will adapt the ./util.js path because Fable doesn't copy JavaScript file to the output.
So if you run dotnet build fable src you will get:
|- src
|- Program.fs
|- Program.fs.js
|- util.js
So it will use import {log} from "./util.js"
But if you run dotnet build fable src --outDir dist/fable then you will get:
And the import statement will be import {log} from "./../../util.js".
Note how both version will still be able to import the util.js file.
If you want your import path to not be rewritten by Fable, you can use ${outDir} macro in the import path and this will tell Fable that you have making your input path relative from the destination folder.
For example, [<Import("log", "${outDir}/util.js")>] but this means that in the second case you will need to move the util.js to the correct place.
MangelMaxime
changed the title
Import attribute changes relative paths when output folder is not equal to fable folder
Why does Import relative paths is changed by Fable depending on the destination ?
Jan 16, 2024
Description
When running the fable compiler,
jsNative
functions with theImport
attribute will change relative import paths if the output folder does not have the same depth as the fable project folder. I have this repo as an example: https://github.com/leononame/fable-reproRepro code
Running:
and
will produce two different files for
Library.js
:and
Expected and actual results
I kinda would expect the import paths to stay constant, not depending on output directory.
Related information
The text was updated successfully, but these errors were encountered: