Example in README does not work ( Latest gleam version )
treuks opened this issue Β· comments
As the title says, if you try to use the example:
Example
import gleam/erlang
import gleam/http/cowboy
import gleam/http/response.{Response}
import gleam/http/request.{Request}
import gleam/bit_builder.{BitBuilder}
// Define a HTTP service
//
pub fn my_service(request: Request(t)) -> Response(BitBuilder) {
let body = bit_builder.from_string("Hello, world!")
response.new(200)
|> response.prepend_header("made-with", "Gleam")
|> response.set_body(body)
}
// Start it on port 3000!
//
pub fn main() {
cowboy.start(my_service, on_port: 3000)
erlang.sleep_forever()
}
Then you will get the following error:
error: Unknown module
ββ ./src/testing_gleam.gleam:1:8
β
1 β import gleam/erlang
β ^^^^^^^^^^^^
No module has been found with the name `gleam/erlang`.
I have tried to look around and try to fix the error but I couldn't really find anything helpful.
Edit: I installed the gleam_erlang
package and that fixed the error, got a new one though.
error: Unknown module
ββ ./src/testing_gleam.gleam:2:8
β
2 β import gleam/http/cowboy
β ^^^^^^^^^^^^^^^^^ Did you mean `erlang`?
No module has been found with the name `gleam/http/cowboy`.
Ok, I fixed the cowboy error by installing gleam_cowboy
(please provide some clearer instructions for the readme), but I got a yet another error related to erlang
error:
error: Unknown module field
ββ ./src/testing_gleam.gleam:21:9
β
21 β erlang.sleep_forever()
β ^^^^^^^^^^^^^^ Did you mean `Errored`?
The module `gleam/erlang` does not have a `sleep_forever` field.
Thank you, I've updated it now.
You may also want to check out the Mist or Elli servers, they are much faster than Cowboy.