Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

New application with buffalo 0.18: could not find templates errors #55

Closed
lsorba opened this issue Nov 26, 2021 · 7 comments · Fixed by gobuffalo/buffalo#2178 or #57
Closed

New application with buffalo 0.18: could not find templates errors #55

lsorba opened this issue Nov 26, 2021 · 7 comments · Fixed by gobuffalo/buffalo#2178 or #57
Assignees

Comments

@lsorba
Copy link

lsorba commented Nov 26, 2021

Hello! Thank you so much for this amazing work.

I am new in the go community, and attempting to get into it through gobuffalo.
I managed to make a basic app with the version 0.17, I updated buffalo yesterday and created a new app and I have wome troubles.
Sorry in advance if it is due to my little experience in go.

Description

I am getting few templating errors while running the application, I attempted to fix one but I am getting others.

Steps to Reproduce the Problem

I am creating an application from scratch using the buffalo new command :

  1. buffalo new app --skip-yarn
  2. buffalo generate resource myres field
  3. buffalo pop create -a
  4. buffalo pop migrate -d
  5. buffalo dev I am getting :
actions/myres.go:9:5: missing go.sum entry for module providing package github.com/gobuffalo/x/responder (imported by app/actions); to add:
        go get app/actions
  1. alright I install app/actions go get app/actions, I alternatively tried go mod tidy
  2. Navigate to http://127.0.0.1:3000/myres/ => HTTP 500
/myres/index.plush.html: could not find template /myres/index.plush.html
  1. Attempt to fix I am removing the leading slash .. sed -i 's/r\.HTML("\//r\.HTML("/' actions/*
  2. Fixed: Navigate to http://127.0.0.1:3000/myres/ => HTTP 200
  3. Navigate to http://127.0.0.1:3000/myres/new/ => HTTP 500
ERRO[2021-11-26T11:35:32+01:00] myres/new.plush.html: line 6: could not call formFor function: could not call partial function: could not find template myres/_form.html content_type=text/html db=0s duration="844.951µs" human_size="0 B" method=GET params="{}" path=/myres/new/ render="239.728µs" request_id=574afe828c378f66fbff-324887f00626b70b5fda size=0 status=500
ERRO[2021-11-26T11:35:33+01:00] could not find favicon.ico status=404
  1. My generated templates folder
├── templates
│   ├── application.plush.html
│   ├── embed.go
│   ├── _flash.plush.html
│   ├── index.plush.html
│   └── myres
│       ├── edit.plush.html
│       ├── _form.plush.html
│       ├── index.plush.html
│       ├── new.plush.html
│       └── show.plush.html

cat templates/myres/new.plush.html

<div class="py-4 mb-2">
  <h3 class="d-inline-block">New Myre</h3>
</div>

<%= formFor(myre, {action: myresPath(), method: "POST"}) { %>
  <%= partial("myres/form.html") %>
  <%= linkTo(myresPath(), {class: "btn btn-warning", "data-confirm": "Are you sure?", body: "Cancel"}) %>
<% } %>

Expected Behavior

My expected behavior is that it is working out of the box (like my first attempts with buffalo 0.17) and also that the dependencies are resolved (if that is the problem).

Info

Please run buffalo info and paste the information below where it says "PASTE_HERE".

-> Go: Checking installation
✓ The `go` executable was found on your system at: /home/lolo/go/go1.17.3/bin/go

-> Go: Checking minimum version requirements
✓ Your version of Go, 1.17.3, meets the minimum requirements.

-> Go: Checking Package Management
✓ You are using Go Modules (`go`) for package management.

-> Go: Checking PATH
✓ Your PATH contains /home/lolo/go/bin.

-> Node: Checking installation
✓ The `node` executable was found on your system at: /usr/local/bin/node

-> Node: Checking minimum version requirements
✓ Your version of Node, v14.16.1, meets the minimum requirements.

-> NPM: Checking installation
✓ The `npm` executable was found on your system at: /usr/local/bin/npm

-> NPM: Checking minimum version requirements
✓ Your version of NPM, 7.23.0, meets the minimum requirements.

-> Yarn: Checking installation
✘ The `yarnpkg` executable could not be found on your system.
For help setting up your Yarn environment please follow the instructions for you platform at:

https://yarnpkg.com/en/docs/install

-> PostgreSQL: Checking installation
✘ The `postgres` executable could not be found on your system.
For help setting up your Postgres environment please follow the instructions for you platform at:

https://www.postgresql.org/download/

-> MySQL: Checking installation
✓ The `mysql` executable was found on your system at: /usr/bin/mysql

-> MySQL: Checking minimum version requirements
✓ Your version of MySQL, 15.1, meets the minimum requirements.

-> SQLite3: Checking installation
✘ The `sqlite3` executable could not be found on your system.
For help setting up your SQLite3 environment please follow the instructions for you platform at:

https://www.sqlite.org/download.html

-> Cockroach: Checking installation
✘ The `cockroach` executable could not be found on your system.
For help setting up your Cockroach environment please follow the instructions for you platform at:

https://www.cockroachlabs.com/docs/stable/

-> Buffalo (CLI): Checking installation
✓ The `buffalo` executable was found on your system at: /home/lolo/go/bin/buffalo

-> Buffalo (CLI): Checking minimum version requirements
✓ Your version of Buffalo (CLI), v0.18.0, meets the minimum requirements.

-> Buffalo: Application Details
Pwd         /tmp/buffalo-test/app
Root        /tmp/buffalo-test/app
GoPath      /home/lolo/go
PackagePkg  app
ActionsPkg  app/actions
ModelsPkg   app/models
GriftsPkg   app/grifts
WithModules true
Name        app
Bin         bin/app
VCS         git
WithPop     true
WithSQLite  false
WithDep     false
WithWebpack true
WithNodeJs  true
WithYarn    false
WithDocker  true
WithGrifts  true
AsWeb       true
AsAPI       false
InApp       true
PackageJSON {map[build:webpack --mode production --progress dev:webpack --watch]}

-> Buffalo: config/buffalo-app.toml
name = "app"
bin = "bin/app"
vcs = "git"
with_pop = true
with_sqlite = false
with_dep = false
with_webpack = true
with_nodejs = true
with_yarn = false
with_docker = true
with_grifts = true
as_web = true
as_api = false

-> Buffalo: config/buffalo-plugins.toml
[[plugin]]
  binary = "buffalo-pop"
  go_get = "github.com/gobuffalo/buffalo-pop/v3@latest"

-> Buffalo: go.mod
module app

go 1.17

require (
        github.com/gobuffalo/buffalo v0.18.0
        github.com/gobuffalo/buffalo-pop/v3 v3.0.1
        github.com/gobuffalo/envy v1.10.1
        github.com/gobuffalo/mw-csrf v1.0.0
        github.com/gobuffalo/mw-forcessl v0.0.0-20200131175327-94b2bd771862
        github.com/gobuffalo/mw-i18n/v2 v2.0.1
        github.com/gobuffalo/mw-paramlogger v1.0.0
        github.com/gobuffalo/pop/v6 v6.0.0
        github.com/gobuffalo/suite/v4 v4.0.2
        github.com/gobuffalo/validate/v3 v3.3.1
        github.com/gobuffalo/x v0.0.0-20190224155809-6bb134105960
        github.com/gofrs/uuid v4.1.0+incompatible
        github.com/markbates/grift v1.5.0
        github.com/unrolled/secure v1.0.9
)

require (
        github.com/BurntSushi/toml v0.4.1 // indirect
        github.com/Masterminds/semver/v3 v3.1.1 // indirect
        github.com/aymerick/douceur v0.2.0 // indirect
        github.com/davecgh/go-spew v1.1.1 // indirect
        github.com/dustin/go-humanize v1.0.0 // indirect
        github.com/fatih/color v1.13.0 // indirect
        github.com/fatih/structs v1.1.0 // indirect
        github.com/felixge/httpsnoop v1.0.1 // indirect
        github.com/fsnotify/fsnotify v1.5.1 // indirect
        github.com/go-sql-driver/mysql v1.6.0 // indirect
        github.com/gobuffalo/events v1.4.2 // indirect
        github.com/gobuffalo/fizz v1.10.0 // indirect
        github.com/gobuffalo/flect v0.2.4 // indirect
        github.com/gobuffalo/github_flavored_markdown v1.1.1 // indirect
        github.com/gobuffalo/helpers v0.6.4 // indirect
        github.com/gobuffalo/httptest v1.5.1 // indirect
        github.com/gobuffalo/logger v1.0.6 // indirect
        github.com/gobuffalo/meta v0.3.1 // indirect
        github.com/gobuffalo/nulls v0.4.1 // indirect
        github.com/gobuffalo/plush/v4 v4.1.9 // indirect
        github.com/gobuffalo/tags/v3 v3.1.2 // indirect
        github.com/gorilla/css v1.0.0 // indirect
        github.com/gorilla/handlers v1.5.1 // indirect
        github.com/gorilla/mux v1.8.0 // indirect
        github.com/gorilla/securecookie v1.1.1 // indirect
        github.com/gorilla/sessions v1.2.1 // indirect
        github.com/inconshreveable/mousetrap v1.0.0 // indirect
        github.com/jackc/chunkreader/v2 v2.0.1 // indirect
        github.com/jackc/pgconn v1.10.1 // indirect
        github.com/jackc/pgio v1.0.0 // indirect
        github.com/jackc/pgpassfile v1.0.0 // indirect
        github.com/jackc/pgproto3/v2 v2.1.1 // indirect
        github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
        github.com/jackc/pgtype v1.8.1 // indirect
        github.com/jackc/pgx/v4 v4.13.0 // indirect
        github.com/jmoiron/sqlx v1.3.4 // indirect
        github.com/joho/godotenv v1.4.0 // indirect
        github.com/karrick/godirwalk v1.16.1 // indirect
        github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
        github.com/luna-duclos/instrumentedsql v1.1.3 // indirect
        github.com/markbates/oncer v1.0.0 // indirect
        github.com/markbates/refresh v1.12.0 // indirect
        github.com/markbates/safe v1.0.1 // indirect
        github.com/markbates/sigtx v1.0.0 // indirect
        github.com/mattn/go-colorable v0.1.9 // indirect
        github.com/mattn/go-isatty v0.0.14 // indirect
        github.com/mattn/go-sqlite3 v1.14.9 // indirect
        github.com/microcosm-cc/bluemonday v1.0.16 // indirect
        github.com/mitchellh/go-homedir v1.1.0 // indirect
        github.com/monoculum/formam v3.5.5+incompatible // indirect
        github.com/nicksnyder/go-i18n v1.10.1 // indirect
        github.com/pelletier/go-toml v1.9.3 // indirect
        github.com/pkg/errors v0.9.1 // indirect
        github.com/pmezard/go-difflib v1.0.0 // indirect
        github.com/rogpeppe/go-internal v1.8.0 // indirect
        github.com/sergi/go-diff v1.2.0 // indirect
        github.com/sirupsen/logrus v1.8.1 // indirect
        github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
        github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
        github.com/spf13/cobra v1.2.1 // indirect
        github.com/spf13/pflag v1.0.5 // indirect
        github.com/stretchr/testify v1.7.0 // indirect
        golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
        golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
        golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
        golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect
        golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
        golang.org/x/text v0.3.6 // indirect
        gopkg.in/yaml.v2 v2.4.0 // indirect
        gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

Thank you in advance!

@fasmat fasmat self-assigned this Nov 26, 2021
@fasmat
Copy link
Member

fasmat commented Nov 26, 2021

The first issue you are reporting is probably caused by a missing go mod tidy or similar in the generate subcommand.
The second issue you are facing is caused by an incomplete template path matcher. Can you try if replacing

//go:embed * _flash.plush.html
var files embed.FS

with

//go:embed * _flash.plush.html
//go:embed myres/*
var files embed.FS

in your templates/embed.go file? Seems like the resource generator needs to be extended to update this file to match the added templates.

@fasmat
Copy link
Member

fasmat commented Nov 26, 2021

@paganotoni can you transfer this issue to the buffalo/cli repo?

@lsorba
Copy link
Author

lsorba commented Nov 26, 2021

Thank you @fasmat for your quick answer !

I realised that I had GO111MODULE set to auto, I updated my env variable to GO111MODULE=on

I did the go mod tidy instead of the go get in step 6

I still have the first problem:

ERRO[2021-11-26T12:30:12+01:00] /myres/index.plush.html: could not find template /myres/index.plush.html content_type=text/html db=4.962387ms duration=6.591717ms human_size="0 B" method=GET params="{}" path=/myres/ render="195.676µs" request_id=574afe828c378f66fbff-7c4f93ea187c4074fa0a size=0 status=500

which requires me to remove the leading flash with sed -i 's/r\.HTML("\//r\.HTML("/' actions/*

Then I can confirm that the go:embed myres/* is helping, my browser can load all the resources (favicon, application.js/css), the create resource page is also now working.

@fasmat
Copy link
Member

fasmat commented Nov 26, 2021

@lsorba: no problem

GO111MODULE=auto is the same as GO111MODULE=on since Go 1.16 and starting with Go 1.18 (to be released in Feb. 2022) this env variable has no effect any more. go get will also be retired in favor of go install (for binaries, dependencies are still added with go get). That's why you might have seen depreciation warnings when using go get.

Regarding the leading slash: this is an issue in the resource generator that was overlooked in the upgrade between 0.17.x and 0.18.0. I will try to fix it, as soon as I get to it.

@paganotoni paganotoni transferred this issue from gobuffalo/buffalo Nov 26, 2021
@corvus-ch
Copy link

I also stumbled on this but in a slight different way.

buffalo new app
cd app
buffalo generate resource message
  1. Fix embed in templates/embed.go
  2. Remove / from template path in resource
diff --git a/actions/messages.go b/actions/messages.go
index 8c3c4b9..8c764ff 100644
--- a/actions/messages.go
+++ b/actions/messages.go
@@ -52,7 +52,7 @@ func (v MessagesResource) List(c buffalo.Context) error {
         c.Set("pagination", q.Paginator)
 
         c.Set("messages", messages)
-        return c.Render(http.StatusOK, r.HTML("/messages/index.plush.html"))
+        return c.Render(http.StatusOK, r.HTML("messages/index.plush.html"))
     }).Wants("json", func (c buffalo.Context) error {
         return c.Render(200, r.JSON(messages))
     }).Wants("xml", func (c buffalo.Context) error {
@@ -80,7 +80,7 @@ func (v MessagesResource) Show(c buffalo.Context) error {
     return responder.Wants("html", func (c buffalo.Context) error {
         c.Set("message", message)
 
-        return c.Render(http.StatusOK, r.HTML("/messages/show.plush.html"))
+        return c.Render(http.StatusOK, r.HTML("messages/show.plush.html"))
     }).Wants("json", func (c buffalo.Context) error {
         return c.Render(200, r.JSON(message))
     }).Wants("xml", func (c buffalo.Context) error {
@@ -93,7 +93,7 @@ func (v MessagesResource) Show(c buffalo.Context) error {
 func (v MessagesResource) New(c buffalo.Context) error {
     c.Set("message", &models.Message{})
 
-    return c.Render(http.StatusOK, r.HTML("/messages/new.plush.html"))
+    return c.Render(http.StatusOK, r.HTML("messages/new.plush.html"))
 }
 // Create adds a Message to the DB. This function is mapped to the
 // path POST /messages
@@ -127,7 +127,7 @@ func (v MessagesResource) Create(c buffalo.Context) error {
             // correct the input.
             c.Set("message", message)
 
-            return c.Render(http.StatusUnprocessableEntity, r.HTML("/messages/new.plush.html"))
+            return c.Render(http.StatusUnprocessableEntity, r.HTML("messages/new.plush.html"))
         }).Wants("json", func (c buffalo.Context) error {
             return c.Render(http.StatusUnprocessableEntity, r.JSON(verrs))
         }).Wants("xml", func (c buffalo.Context) error {
@@ -165,7 +165,7 @@ func (v MessagesResource) Edit(c buffalo.Context) error {
     }
 
     c.Set("message", message)
-    return c.Render(http.StatusOK, r.HTML("/messages/edit.plush.html"))
+    return c.Render(http.StatusOK, r.HTML("messages/edit.plush.html"))
 }
 // Update changes a Message in the DB. This function is mapped to
 // the path PUT /messages/{message_id}
@@ -202,7 +202,7 @@ func (v MessagesResource) Update(c buffalo.Context) error {
             // correct the input.
             c.Set("message", message)
 
-            return c.Render(http.StatusUnprocessableEntity, r.HTML("/messages/edit.plush.html"))
+            return c.Render(http.StatusUnprocessableEntity, r.HTML("messages/edit.plush.html"))
         }).Wants("json", func (c buffalo.Context) error {
             return c.Render(http.StatusUnprocessableEntity, r.JSON(verrs))
         }).Wants("xml", func (c buffalo.Context) error {
diff --git a/templates/embed.go b/templates/embed.go
index c5f0fca..bda6d0e 100644
--- a/templates/embed.go
+++ b/templates/embed.go
@@ -6,6 +6,7 @@ import (
 )
 
 //go:embed * _flash.plush.html
+//go:embed messages/*
 var files embed.FS
 
 func FS() fs.FS {

@sio4
Copy link
Member

sio4 commented Nov 27, 2021

Requested two PRs to fix this issue. One for template searching issue, another for leading slash issue.

@fasmat
Copy link
Member

fasmat commented Nov 27, 2021

@sio4 thanks for taking over fixing this issue. @paganotoni with the two PRs this issue should be fixed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants