djc / askama

Type-safe, compiled Jinja-like templates for Rust
Apache License 2.0
3.25k stars 213 forks source link

Unable to publish package containing askama #1074

Closed roberte777 closed 3 weeks ago

roberte777 commented 3 weeks ago

Hello there!

I am using askama for a project I want to publish to a registry (not crates.io, but that should not be the issue here). However, when trying to run the publish command, the project fails to build. This is odd since a regular cargo build --release works fine. Here is the error I am getting:

error: template "main.rs" not found in directories ["/home/roberte777/coding/rust/cargo-vct-help/target/package/cargo-vct-help-0.1.0/templates"]
 --> src/templates.rs:4:10
  |
4 | #[derive(Template)]
  |          ^^^^^^^^
  |
  = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

error: template "handlers.rs" not found in directories ["/home/roberte777/coding/rust/cargo-vct-help/target/package/cargo-vct-help-0.1.0/templates"]
  --> src/templates.rs:10:10
   |
10 | #[derive(Template)]
   |          ^^^^^^^^
   |
   = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

error: template "Cargo.toml" not found in directories ["/home/roberte777/coding/rust/cargo-vct-help/target/package/cargo-vct-help-0.1.0/templates"]
  --> src/templates.rs:17:10
   |
17 | #[derive(Template)]
   |          ^^^^^^^^
   |
   = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `render` found for struct `ServiceTemplate` in the current scope
  --> src/lib.rs:64:45
   |
64 |     let service_rendered = service_template.render().unwrap();
   |                                             ^^^^^^ method not found in `ServiceTemplate`
   |
  ::: src/templates.rs:6:1
   |
6  | pub struct ServiceTemplate {
   | -------------------------- method `render` not found for this struct
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `render`, perhaps you need to implement it:
           candidate #1: `Template`

error[E0599]: no method named `render` found for struct `HandlerTemplate` in the current scope
  --> src/lib.rs:65:45
   |
65 |     let handler_rendered = handler_template.render().unwrap();
   |                                             ^^^^^^ method not found in `HandlerTemplate`
   |
  ::: src/templates.rs:12:1
   |
12 | pub struct HandlerTemplate {
   | -------------------------- method `render` not found for this struct
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `render`, perhaps you need to implement it:
           candidate #1: `Template`

error[E0599]: no method named `render` found for struct `CargoTemplate` in the current scope
  --> src/lib.rs:66:41
   |
66 |     let cargo_rendered = cargo_template.render().unwrap();
   |                                         ^^^^^^ method not found in `CargoTemplate`
   |
  ::: src/templates.rs:19:1
   |
19 | pub struct CargoTemplate {
   | ------------------------ method `render` not found for this struct
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `render`, perhaps you need to implement it:
           candidate #1: `Template`

Looking in the target directory, I definitely don't see the templates folder. Is there something different here that results in that folder not being moved over like it would be in a regular build?

I have also tried to make the templates folder be moved over to the package dir by adding it in the include field in the Cargo.toml: include = ["static/**","templates/**", "src/**", "Cargo.toml", "Cargo.lock"]

This seems to have worked fine for my static dir but not the templates dir for whatever reason. Static dir gets moved over but templates does not.

roberte777 commented 3 weeks ago

it wasn't working because i had Cargo.toml in the templates folder