dokuzbir

dokuzbir

Drab webpack problem - Uncaught ReferenceError: require is not defined

I am trying to use drab with webpack but i get error in drap.js

Uncaught ReferenceError: require is not defined
this.Socket = require("phoenix").Socket;

I tried to add that to in app.js
window.socket = require("phoenix").Socket
and i changed
this.Socket = window.socket

But get new error this.Socket is not a constructor. How can i use drab with webpack ?

First Post!

grych

grych

Creator of Drab

Hi @dokuzbir,
yes, Drab does it:

window.Drab = {
  create: function (drab_return_token, drab_session_token, broadcast_topic) {
    this.Socket = require("phoenix").Socket;

And webpack does not provide global require. We had some discussions about it in github before, but I still can’t find the more universal way to initialize Socket.

Most Liked

grych

grych

Creator of Drab

There is no better way to learn than contributing to an opensource project, IMO.

grych

grych

Creator of Drab

Of course everyone is invited! More brains!

Don’t worry if you find it complicated. Some parts are, but you can always start with the easier stuff, then get deeper and help refactor the core code. I could suggest few areas to work with:

  • Issues: check the issues list, the ones marked with “help wanted” are waiting for you! There is one marked as “level: beginner”, should be quite easy to jump into.

  • Documentation: Drab is the software for developers, so documentation is at least the same important as the code. It needs review, clarification. There are for sure many parts which are understandable for me, but not for others. Also, starting with docs would let you learn how Drab works

  • Tutorial and examples: there is a page, Drab: Server Side User Interface Access, with few examples. It also could be improved, more interesting examples added. José suggested creating the example app with multiple chat rooms - maybe something like slack? - I think it is a good idea, but I never had time to do it. There is also a need to write a real beginners guide. I was even thinking about writing a complete beginners guide (with short introduction to elixir, phoenix, html and css). I want Drab to be a good way for beginners to start doing webapps without scary JS frameworks.

  • Code review: Drab started as a proof of concept, and had thousands of twists in its history. There is a lot to improve with code readability. Sometime I am wondering how does it works :wink: Again, this would be a good exercise and way to learn how it works.

Zesky665

Zesky665

About the multi chat room tutorial, I’m doing something similar for my graduation thesis and I’m in the process or rebuilding it with drab. Would anyone be interested in a tutorial?

Last Post!

thib

thib

thanks it works so well and the fix is so simple… :slight_smile:

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement