Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elm integration broken #1668

Closed
ngw opened this issue Aug 24, 2018 · 9 comments
Closed

Elm integration broken #1668

ngw opened this issue Aug 24, 2018 · 9 comments

Comments

@ngw
Copy link

ngw commented Aug 24, 2018

Since the release of Elm 0.19 elm integration on webpacker is broken.

https://gist.github.com/ngw/0bc000fdf484a70dbc9693142790d2f0

 ngw@bluemonday ~ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]

 ngw@bluemonday ~ elm --version
0.19.0

 ngw@bluemonday ~ rails -v
Rails 5.2.1 

Gemfile.lock: https://gist.github.com/ngw/4aa6e1ebb4de91c464554c91665f9625

@noelrappin
Copy link

This is probably blocked until elm-webpack-loader updates elm-community/elm-webpack-loader#142

@dmerand
Copy link

dmerand commented Aug 30, 2018

I'm having this issue as well. It looks like elm-webpack-loader was updated earlier today, so hopefully this is no longer blocked. Thanks!

@ngw
Copy link
Author

ngw commented Sep 3, 2018

@dmerand I'd say still broken. I'm stuck with 0.18 unless I'm missing something.

@dmerand
Copy link

dmerand commented Sep 4, 2018

@ngw Oh it's definitely still broken. I was able to work around it, but it took quite a few manual steps, mostly around new Elm binary commands. Lemme see if I can summarize from memory...

https://github.com/rails/webpacker/blob/master/lib/install/elm.rb is where most of the problems lie, starting at line 25:

#run "yarn add --dev elm-hot-loader"
run "yarn add --dev elm-hot-webpack-loader"
#run "yarn run elm package install -- --yes"
run "yarn run elm init"
run "yarn run elm make"

say "Updating webpack paths to include .elm file extension"
insert_into_file Webpacker.config.config_path, "- .elm\n".indent(4), after: /extensions:\n/

say "Updating Elm source location"
#gsub_file "elm-package.json", /\"\.\"\n/,
gsub_file "elm-package.json", /\"\src\"\n/,
  %("#{Webpacker.config.source_path.relative_path_from(Rails.root)}"\n)

say "Updating .gitignore to include elm-stuff folder"
insert_into_file ".gitignore", "/elm-stuff\n", before: "/node_modules\n"\

... and then in https://github.com/rails/webpacker/blob/master/lib/install/loaders/elm.js you have to make some mods too:

//const elmMake = `${elmSource}/node_modules/.bin/elm-make`
const elmMake = `${elmSource}/node_modules/.bin/elm`

//...

const developmentOptions = Object.assign({}, elmDefaultOptions, {
  verbose: true,
  //warn: true,
  debug: true
})


const elmWebpackLoader = {
  //loader: 'elm-webpack-loader',
  loader: 'elm-hot-webpack-loader',
  options: isProduction ? elmDefaultOptions : developmentOptions
}

This got it mostly working for me, except for a slight change I had to make to elm-hot to make live-reloading work.

@ngw
Copy link
Author

ngw commented Sep 4, 2018

Can't you turn this into a PR?

@dmerand
Copy link

dmerand commented Sep 5, 2018

@ngw I'm not comfortable turning it into a PR because I'm not familiar with this full codebase, nor do I have time to get that familiar. Running the steps above by hand worked for me, but I'm not set up to test my changes against this entire repo. Hopefully what's there will be helpful to a maintainer in creating a more complete PR.

@ngw
Copy link
Author

ngw commented Sep 10, 2018

The command that generates the error does exactly tha same thing as before, the package hasn't been released so there's no way to validate the fix.

I manually changed loaders/elm.js because AFAIK that is the only way, still in some kind of dependency hell where different parts of the framework (webpack-dev-server, babel) fail with the most cryptic errors possible.

Right now I'm having:

Module build failed: Error: Compiled JS from the Elm compiler is not valid. You must use the Elm 0.19 compiler.

I've deleted tmp/cache and there's no 0.18 on my system

ngw@bluemonday ~/directory email_validation ● elm --version
0.19.0
ngw@bluemonday ~/directory email_validation ● node_modules/.bin/elm --version
0.19.0

@klazuka
Copy link
Contributor

klazuka commented Sep 10, 2018

@ngw that error comes from my elm-hot package https://github.com/klazuka/elm-hot/blob/d4bd8be7d266db2fa5ffa145f32c1f3d444b730a/src/inject.js#L35. There's a check for Elm 0.18 earlier in that function, so I don't think the problem is that Elm 0.18 is slipping through. The problem seems to be with finding the place within the huge Elm IIFE to splice the HMR code into. I don't actually use rails/webpacker, but someone said that they do some JS injection of their own. Maybe the code that they are adding is breaking my regex?

Can you try downloading and modifying elm-hot to dump out the contents of what it's receiving from rails/webpacker as the parameter to the inject function?

@aruprakshit
Copy link

I am still getting the same error as the original poster posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants