Fable
Fable copied to clipboard
Imports for FSX files have wrong extension.
Description
When loading a FSX script inside another, it is found and transpiled correctly, but the import statement generated uses the fsx extension instead of the correct .fs.js extension.
Repro code
Contents of a.fsx:
let a v = v + 1
Contents of main.fsx:
#load "a.fsx"
open A
let b v = a v + 1
Build with the following:
fable main.fsx --run "esbuild --bundle --outfile=main.bundle.js main.fs.js"
Output in main.fs.js (with incorrect import):
import { a } from "./a.fsx";
export function b(v) {
return a(v) + 1;
}
ESBuild fails with the following:
No loader is configured for ".fsx" files: a.fsx
Expected and actual results
Output in main.fs.js should have the correct .fs.js extension:
import { a } from "./a.fs.js";
Related information
- Fable version:
4.11.0(installed globally) - Operating system: Windows 11 22H2 (22621.3007)
I can see some extension handling in https://github.com/fable-compiler/Fable/blob/main/src/fable-compiler-js/src/app.fs
Within member _.MakeImportPath(path) in interface Fable.Standalone.IWriter of SourceWriter:
if path.EndsWith(".fs") then
Maybe fixed as the following:
if path.EndsWith(".fs") || path.EndsWith(".fsx") then
Files in fable-compiler-js is when using the fable-compiler-js NPM package it is not what most people use.
Most people consume Fable via .NET which code is located in src/Fable.CLI, src/ Fable.Compiler, src/Fable.Transforms, etc.
So I don't think the file linked will be what is needed to fix your problem.