Core: File is not defined in Node

Created on 15 Nov 2018  路  8Comments  路  Source: elm/core

When running in Node, this line will cause ReferenceError: File is not defined:

https://github.com/elm/core/blob/4fde3f08f276b159176d535db4e9591101a95c1e/src/Elm/Kernel/Debug.js#L151

---- Elm 0.19.0 ----------------------------------------------------------------
Read <https://elm-lang.org/0.19.0/repl> to learn more: exit, help, imports, etc.
--------------------------------------------------------------------------------
> type alias Test = { bla : Int }
> Test 1
ReferenceError: File is not defined>

This error can also be seen when using elm-test.

Most helpful comment

Thank you @doanythingfordethklok for confirming the fix! And thank you @SidneyNemzer for stripping all the extra stuff from the example and showing the line of code. Very helpful!

Also, I am doing an equivalent fix in elm/file because this value instanceof File pattern appears there in the file decoder. So that should be fine soon. But if there are any other problems like this, please let me know.

All 8 comments

Maybe File can be added here in node-test-runner? https://github.com/rtfeldman/node-test-runner/blob/master/templates/before.js

It will still not work in the repl though.

I can do the same check as with DataView a couple lines above:

if (typeof File === 'function' && value instanceof File)
{
    return _Debug_internalColor(ansi, '<' + value.name + '>');
}

I believe the only ways to get File values are:

  1. Decoding DOM events
  2. Creating a Cmd with File.Select

I think that means that it will not be possible to get File values in the REPL, but there may need to be similar checks in elm/file in case people have that as a dependency.

Fix should be available in 1.0.2

This works great. Thank y'all so much for fixing so quickly!

Thank you @doanythingfordethklok for confirming the fix! And thank you @SidneyNemzer for stripping all the extra stuff from the example and showing the line of code. Very helpful!

Also, I am doing an equivalent fix in elm/file because this value instanceof File pattern appears there in the file decoder. So that should be fine soon. But if there are any other problems like this, please let me know.

@evancz I updated elm/json and got the same issue with FileList: https://github.com/elm/json/blob/84ecbaa4d95e936fd67e156aa99dacbb4e91b972/src/Elm/Kernel/Json.js#L331

This test failed because it threw an exception: "ReferenceError: FileList is not defined"

This was polyfilled yesterday by @rtfeldman. So it would occur in previous versions of elm-test, but it's fixed in the current. https://github.com/rtfeldman/node-test-runner/commit/2ed1e38772c28e323f64ba98ddb1c1f54023c2dd#diff-11c235e88b2066e030399d9b03ecc1df

For consistency and repl / serviceworkers it should probably handled the same way as File ;)

@evancz it's the same for FileList in elm/json FYI - we're now polyfilling that in elm-test but it probably affects repl too!

Thank you for letting me know. I made a check for it in 1.1.2 of elm/json.

If there are further problems, please make fresh issues and leave out any winky faces.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

keithasaurus picture keithasaurus  路  6Comments

liamcurry picture liamcurry  路  4Comments

zwilias picture zwilias  路  4Comments

Fresheyeball picture Fresheyeball  路  8Comments

rtfeldman picture rtfeldman  路  8Comments