christophp / elm-esm Goto Github PK
View Code? Open in Web Editor NEWTurn Elm compiler output into modern ES Modules
Home Page: https://www.npmjs.com/package/elm-esm
Turn Elm compiler output into modern ES Modules
Home Page: https://www.npmjs.com/package/elm-esm
Something crashed unexpectedly. Please open an issue with this error message. https://github.com/ChristophP/elm-esm/issues/new
TypeError: Cannot read properties of null (reading 'toString')
at findElmBinary (C:\Users\<user>\AppData\Roaming\npm\node_modules\elm-esm\src\run.js:15:12)
at delegateToElmCompiler (C:\Users\<user>\AppData\Roaming\npm\node_modules\elm-esm\src\run.js:50:27)
at run (C:\Users\<user>\AppData\Roaming\npm\node_modules\elm-esm\src\run.js:65:9)
at Object.<anonymous> (C:\Users\<users>\AppData\Roaming\npm\node_modules\elm-esm\src\run.js:71:1)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
Thanks for sharing such a useful implementation โจ
One thing I'd like to request is that the distributed elm-esm
npm provides importable makeESModule
.
I'm imagining an interface like:
import { toESM } from 'elm-esm'
toESM(compiledElmProject)
I could build my own function by copying your code actually. However, I'm wondering if elm-esm
becomes a single source of truth for this purpose in the community, and we can contribute when Elm core changes outcome in the future.
Hello,
the following bug was created on my https://github.com/marc136/snowpack-plugin-elm/issues/3 by @andreasewering
And as I copied the code to turn the compiled elm code into an es module from your repository, I think the change should also be propagated into your tool.
I fixed it in my repo with this change.
Regards,
marc
Full description
When comipling the following file with npx elm-esm make src/DocumentWithFlags.elm --output=elm-esm-output.js
, you can open the compiled js output and will notice that at the end the call to _Platform_export
is not fully replaced.
module DocumentWithFlags exposing (main)
import Browser
import Html exposing (..)
import Json.Decode
type alias Flags =
-- Json.Decode.Value -- this would work
{ test : String }
main : Program Flags Model Msg
main =
Browser.document
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
type alias Model =
{ property : String
}
init : Flags -> ( Model, Cmd Msg )
init _ =
( Model "", Cmd.none )
type Msg
= Msg1
| Msg2
update : Msg -> Model -> ( Model, Cmd Msg )
update _ model =
( model, Cmd.none )
subscriptions : Model -> Sub Msg
subscriptions _ =
Sub.none
view : Model -> Browser.Document Msg
view _ =
{ title = "Document Title"
, body =
[ h1 [] [ text "loaded" ] ]
}
The output ends with the following lines:
var $author$project$DocumentWithFlags$main = $elm$browser$Browser$document(
{init: $author$project$DocumentWithFlags$init, subscriptions: $author$project$DocumentWithFlags$subscriptions, update: $author$project$DocumentWithFlags$update, view: $author$project$DocumentWithFlags$view});
/*
_Platform_export({'DocumentWithFlags':{'init':$author$project$DocumentWithFlags$main(
A2(
$elm$json$Json$Decode$andThen,
function (test) {
return $elm$json$Json$Decode$succeed(
{test: test});
*/
},
A2($elm$json$Json$Decode$field, 'test', $elm$json$Json$Decode$string)))(0)}});}(this));
export const Elm = {'DocumentWithFlags':{'init':$author$project$DocumentWithFlags$main(
A2(
$elm$json$Json$Decode$andThen,
function (test) {
return $elm$json$Json$Decode$succeed(
{test: test};
But it should be:
var $author$project$DocumentWithFlags$main = $elm$browser$Browser$document(
{au: $author$project$DocumentWithFlags$init, aB: $author$project$DocumentWithFlags$subscriptions, aD: $author$project$DocumentWithFlags$update, aE: $author$project$DocumentWithFlags$view});
/*
_Platform_export({'DocumentWithFlags':{'init':$author$project$DocumentWithFlags$main(
A2(
$elm$json$Json$Decode$andThen,
function (test) {
return $elm$json$Json$Decode$succeed(
{ag: test});
},
A2($elm$json$Json$Decode$field, 'test', $elm$json$Json$Decode$string)))(0)}});}(this));
*/
export const Elm = {'DocumentWithFlags':{'init':$author$project$DocumentWithFlags$main(
A2(
$elm$json$Json$Decode$andThen,
function (test) {
return $elm$json$Json$Decode$succeed(
{ag: test});
},
A2($elm$json$Json$Decode$field, 'test', $elm$json$Json$Decode$string)))(0)}});};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.