elm-webpack-loader icon indicating copy to clipboard operation
elm-webpack-loader copied to clipboard

Nested `Elm` variable when using webpack2

Open zgohr opened this issue 5 years ago • 5 comments

I tried to reproduce this with the included webpack2 example but I couldn't get that one running.

The issue is that using webpack2 seems to nest the Elm javascript variable.

Example (working code):

var Elm = require('./Main')
Elm.Elm.Main.init({node: document.getElementById('main')});

Found this while upgrading elm-select here

zgohr avatar Aug 30 '18 17:08 zgohr

Same here https://github.com/sporto/elm-webpack-serve-repro/blob/master/src/app.js#L5

sporto avatar Sep 03 '18 10:09 sporto

PRs welcome

eeue56 avatar Sep 03 '18 14:09 eeue56

Have confirmed this is also happening with WP4 and Elm 0.19.

RaniSputnik avatar Sep 16 '18 16:09 RaniSputnik

For those of us using es6 modules, this did the trick for me:

import { Elm } from '../elm/src/Main.elm'

Elm.Main.init({ node: document.getElementById('elm') })

As noted above, you can also do this:

import Elm from '../elm/src/Main.elm'

Elm.Elm.Main.init({ node: document.getElementById('elm') })

embryCODE avatar Oct 17 '18 14:10 embryCODE

import { Elm } from '../elm/src/Main.elm'

Elm.Main.init({ node: document.getElementById('elm') })

This also worked for me, using webpack 5 with Typescript and Elm 0.19.1

tsopeh avatar Mar 10 '21 07:03 tsopeh