Fable icon indicating copy to clipboard operation
Fable copied to clipboard

Fable cannot import modules beginning with a number

Open rdparker opened this issue 8 years ago • 3 comments

Description

Importing Javascript modules that begin with a number fails, for example 7zip-bin.

Repro code

dotnet new -i Fable.Template
dotnet new fable -n FableImportBug -lang F#
cd FableImportBug
yarn add 7zip-bin
yarn

Replace App.js with:

module FableImportBug

open Fable.Core.JsInterop
open Fable.Import

let init() =
    let sevenZipBin : obj = importAll "7zip-bin"
    Browser.console.log sevenZipBin?path7za

init()
yarn start

Expected and actual results

The above should succeed and the path to 7zip should be displayed in the console when the page is opened. Instead the following errors will be produced:

D:\repos\FableImportBug>yarn start
openssl config failed: error:02001003:system library:fopen:No such process
yarn run v1.6.0
$ cd tools && dotnet fable webpack-dev-server -- --config webpack.config.dev.js
Fable (1.3.8) daemon started on port 61225
CWD: D:\repos\FableImportBug\tools
cmd /C node "D:\repos\FableImportBug\node_modules\webpack-dev-server\bin\webpack-dev-server.js" --config webpack.config.dev.js
openssl config failed: error:02001003:system library:fopen:No such process
Bundling for development...
Project is running at http://localhost:8080/
webpack output is served from /
Content not from webpack is served from D:\repos\FableImportBug\public
Parsing ../src/FableImportBug.fsproj...
fable: Compiled ..\src\FableImportBug.fsproj
fable: Compiled ..\src\App.fs
Hash: 5bed16fcc31ec37614a5
Version: webpack 3.8.1
Time: 9519ms
      Asset       Size  Chunks                    Chunk Names
    main.js     356 kB       0  [emitted]  [big]  main
main.js.map     418 kB       0  [emitted]         main
 index.html  521 bytes          [emitted]
[../node_modules/ansi-regex/index.js] ../node_modules/ansi-regex/index.js 135 bytes {0} [built]
[../node_modules/loglevel/lib/loglevel.js] ../node_modules/loglevel/lib/loglevel.js 7.86 kB {0} [built]
[../src/App.fs] ../src/App.fs 248 bytes {0} [built] [failed] [1 error]
   [0] multi ../node_modules/webpack-dev-server/client?http://localhost:8080 webpack/hot/dev-server ../src/FableImportBug.fsproj 52 bytes {0} [built]
[../node_modules/strip-ansi/index.js] ../node_modules/strip-ansi/index.js 161 bytes {0} [built]
[../node_modules/url/url.js] ../node_modules/url/url.js 23.3 kB {0} [built]
[../node_modules/webpack-dev-server/client/index.js?http://localhost:8080] ../node_modules/webpack-dev-server/client?http://localhost:8080 7.95 kB {0} [built]
[../node_modules/webpack-dev-server/client/overlay.js] ../node_modules/webpack-dev-server/client/overlay.js 3.73 kB {0} [built]
[../node_modules/webpack-dev-server/client/socket.js] ../node_modules/webpack-dev-server/client/socket.js 1.05 kB {0} [built]
[../node_modules/webpack/hot ^\.\/log$] ../node_modules/webpack/hot nonrecursive ^\.\/log$ 170 bytes {0} [built]
[../node_modules/webpack/hot/dev-server.js] ../node_modules/webpack/hot/dev-server.js 1.56 kB {0} [built]
[../node_modules/webpack/hot/emitter.js] ../node_modules/webpack/hot/emitter.js 75 bytes {0} [built]
[../node_modules/webpack/hot/log-apply-result.js] ../node_modules/webpack/hot/log-apply-result.js 1.27 kB {0} [built]
[../node_modules/webpack/hot/log.js] ../node_modules/webpack/hot/log.js 1 kB {0} [built]
[../src/FableImportBug.fsproj] ../src/FableImportBug.fsproj 25 bytes {0} [built]
    + 14 hidden modules

ERROR in ../src/App.fs
Module parse failed: Identifier directly after number (1:13)
You may need an appropriate loader to handle this file type.
| import * as 7zip_bin from "7zip-bin";
| export function init() {
|     var sevenZipBin = 7zip_bin;
@ ../src/FableImportBug.fsproj 1:0-25
@ multi ../node_modules/webpack-dev-server/client?http://localhost:8080 webpack/hot/dev-server ../src/FableImportBug.fsproj
Child html-webpack-plugin for "index.html":
    1 asset
    [../node_modules/html-webpack-plugin/lib/loader.js!../src/index.html] ../node_modules/html-webpack-plugin/lib/loader.js!../src/index.html 758 bytes {0} [built]
    [../node_modules/lodash/lodash.js] ../node_modules/lodash/lodash.js 540 kB {0} [built]
    [../node_modules/webpack/buildin/global.js] ../node_modules/webpack/buildin/global.js 488 bytes {0} [built]
    [../node_modules/webpack/buildin/module.js] ../node_modules/webpack/buildin/module.js 495 bytes {0} [built]
webpack: Failed to compile.

Related information

  • Fable version (dotnet fable --version): 1.3.15
  • Operating system: Windows 10 Pro

I have found and fixed the issue in Fable.Core and have added unit tests for it. It is available on the feature/fix-import-initial-number branch of my Fable repo.

I would like to test it with my project where this fails before issuing a pull request. @MangelMaxime suggested on gitter that I open an issue to find out how to do that.

Thanks for such an incredible tool.

rdparker avatar May 04 '18 19:05 rdparker

After you run the build script, I think you should be able to do dotnet path/to/fable.dll instead of dotnet fable.

inosik avatar May 04 '18 19:05 inosik

Thanks, dotnet path/to/dotnet-fable.dll did the trick.

The App.js above doesn't display what I expected in the console, but it compiles now, which was the point. It was just a minimal sample of the import problem.

I'll start testing the changes with my app that was having problems with electron-devtools-installer not extracting the devtools properly and see if that works.

rdparker avatar May 04 '18 21:05 rdparker

Thanks to you for your report @rdparker! And sorry, I was skimming through the issues and went to the code directly after reading the error output, before noticing you already fixed it! 🤦‍♂️ 😅 I published a new version with the fix (1.3.16) but I'll accept a PR if you want to send it as you also included some tests :+1:

alfonsogarciacaro avatar May 05 '18 17:05 alfonsogarciacaro