Fable: fable-core folder and content is not created in output of multi project solution.

Created on 10 Jul 2017  路  7Comments  路  Source: fable-compiler/Fable

Description

Compilation of multi project solution does not create fable-core folder and it's content in the output directory.

Repro code

npm5 is required.

steps to reproduce:

git clone https://github.com/ed-ilyin/FableCoreOutputProblem.git
cd FableCoreOutputProblem
npm install
dotnet restore
rm -rf out
cd src/App
dotnet fable npm-run split
cd ../..
node out/FableCoreOutputProblem/App.js

Expected and actual results

Expecting run without error, but instead following error occurs:

module.js:487
    throw err;
    ^

Error: Cannot find module '../fable-core/String'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/out/FableCoreOutputProblem/App.js:3:15)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)

Related information

  • Fable version (dotnet fable --version): 1.1.8
  • Operating system: macOS Sierra 10.12.5

Most helpful comment

Sorry tried provided solutions and now everything works. Thank you both very much. 馃榿 馃槃 馃槂

All 7 comments

Ah, you're using the splitter! I'm not sure about this as I normally use a bundler like Webpack/Rollup so fable-core files get embedded automatically in the bundle. Do you have any plan about this @ncave? Maybe we can copy the fable-core folder from the Fable.Core package to outDir by default and use that reference?

@ed-ilyin For now, you can do the copy manually (maybe in your build script) and pass the fable-core patch using the fableCore option for the splitter.

The problem is the different working directory contexts, dotnet fable command is running in src/App but npm scripts run in root. Unfortunately I can't fix that as I don't know what the root is in this case.
It's probably better if we find a way to run the dotnet fable from the root of the project where the npm scripts are, then the splitter config can move to the root too.

@ncave if I have multiple projects, then I can have multiple splitter configs, one per project.

@ed-ilyin If those are unrelated projects (that don't reference each other), then yes, makes sense, but then you wouldn't have a single "split" script in the package.json. Which leads to the solution: Create a small package.json with just the split script in each project you're running fable from, i.e. in this case create src/App/package.json like that:

{
  "scripts": {
    "split": "node splitter.config.js"
  }
}

and change the outDir in splitter.config to outDir: "../../out".

That fixes it for me, I can now run node out/App/App.js

As a note, you can also use the node-run command with Fable instead of adding the package.json: dotnet fable node-run splitter.config.js

My story:
In my solution I have Client project (1) and Server project (2) which share common Types and shared code project (3).
Client and Server projects have to be built using different setting, since Server part for Node and Client part for browser.

Anyway, I have partly fixed my example, by adding to fableOptions fableCore path:

const fableOptions = {
  fableCore: resolve("./packages/Fable.Core/fable-core")
}

But still some files referenced from Api project do not compile:

> node src/App/splitter.config.js

Fable compiler started ...
Parsing ./App.fsproj...
Fable compiled: /Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/App.fs
Fable compiled: /Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/packages/Fable.Core/fable-core/String.js
Fable compiled: /Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/packages/Fable.Core/fable-core/Date.js
Fable compiled: /Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/packages/Fable.Core/fable-core/Long.js
Fable compiled: /Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/packages/Fable.Core/fable-core/Int32.js
Fable compiled: /Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/packages/Fable.Core/fable-core/Symbol.js
Fable compiled: /Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/packages/Fable.Core/fable-core/TimeSpan.js
Fable compiled: /Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/packages/Fable.Core/fable-core/Util.js
Fable compiled: /Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/packages/Fable.Core/fable-core/RegExp.js
Fable compiled: /Users/ed/git/github.com/ed-ilyin/Api/Api.fs
Fable compiler is done.
Closing Fable daemon...
> node out/FableCoreOutputProblem/App.js
module.js:487
    throw err;
    ^

Error: Cannot find module '../fable-core/Result'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/ed/git/github.com/ed-ilyin/FableCoreOutputProblem/out/Api/Api.js:8:15)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)

Sorry tried provided solutions and now everything works. Thank you both very much. 馃榿 馃槃 馃槂

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments

MangelMaxime picture MangelMaxime  路  3Comments

jwosty picture jwosty  路  3Comments

et1975 picture et1975  路  3Comments

tomcl picture tomcl  路  4Comments