<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="356052" data-post-id="356052">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="skyturtle" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/skyturtle/120/21845_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  skyturtle
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hey! I updated and <code>mix assets.deploy</code> worked and the Docker image was able to be built. Thanks for making the changes!</p>
<p>After the update, everything continued to work fine in <code>dev</code> mode, but I ran into a few more issues with the deployed application. Here they are in the order I found them in the logs and the changes I made to fix them:</p>
<ol>
<li><code>(UndefinedFunctionError) function Mix.env/0 is undefined (module Mix is not available)</code></li>
</ol>
<p>The function <code>dev_env?/0</code> was being invoked in the <code>*.html.heex</code> files, which was causing the error. In the layouts module e.g. <code>myapp_web/components/layouts.ex</code> I added a module attribute so that the environment would be remembered at compile time:</p>
<pre data-code-wrap="diff"><code class="lang-diff">- def dev_env? do
-    Mix.env() == :dev
- end  
  # Remember value at compile time since Mix is
  # not available at runtime
+ @env Mix.env()
+ def dev_env?, do: @env == :dev
</code></pre>
<ol start="2">
<li><code>vite_manifest.json</code> no such file or directory error</li>
</ol>
<p>In my server logs, I was seeing</p>
<pre data-code-wrap="shell"><code class="lang-shell">(File.Error) could not read file "priv/static/assets/vite_manifest.json": no such file or directory
</code></pre>
<p>I shelled into the Docker container to see if the assets were being generated. They <strong>were</strong> being generated so I checked out the <code>PhxManifestReader</code> module. I noticed that <code>do_read/1</code> was using <code>current_env/0</code>. I think the issue was this line</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">      Application.get_env(:exinertia_demo, :env, Vite.default_env())
</code></pre>
<p>I <em>think</em> this was returning <code>nil</code> in production, but I’m not positive. Anyway, in <code>config.exs</code> I added <a href="https://hexdocs.pm/elixir/Config.html#config_env/0" rel="noopener nofollow ugc"><code>config_env/0</code></a> so that the <code>config</code> file would know what environment <code>mix release</code> was run in</p>
<pre data-code-wrap="diff"><code class="lang-diff">config :exinertia_demo,
  ecto_repos: [ExinertiaDemo.Repo],
+ env: config_env(),
  generators: [timestamp_type: :utc_datetime_usec, binary_id: true]
</code></pre>
<ol start="3">
<li>404 for <code>*.js</code> files</li>
</ol>
<p>After the <code>vite_manifest</code> was read correctly, the webpages would finally load, but no <code>*.js</code> files could be found. As a result, pages rendered by Inertia.js were blank. I checked the source and logs and saw:</p>
<pre data-code-wrap="html"><code class="lang-html">&lt;script type="module" crossorigin="" defer="" phx-track-static="" src="/app.CR82hMY-.js"&gt;
  &lt;/script&gt;
</code></pre>
<pre data-code-wrap="shell"><code class="lang-shell">03:12:12.408 request_id=GCMIxx8X9K92UAIAAArB [info] GET /app.CR82hMY-.js
03:12:12.408 request_id=GCMIxx8X9K92UAIAAArB [info] Sent 404 in 189µs
</code></pre>
<p>CSS was working fine and I noticed <code>/assets/</code> was missing on the <code>src</code> path. I’m not sure if it was supposed to be prepended after being read in <code>PhxManifestReader</code>, but I just updated the <code>src</code> for the layouts and prepended <code>assets</code> using string interpolation. I’m not sure if the other attributes on the script tag e.g. <code>crossorigin</code>, <code>defer</code>, are supposed to be something other than an empty string, but everything seems to be working right now.</p>
<pre data-code-wrap="diff"><code class="lang-diff">- src={Vite.Manifest.main_js()}&gt;
+ src={"/assets/#{Vite.Manifest.main_js()}"}
</code></pre>
<p>I have the code up on Github <a href="https://github.com/skyturtleio/exinertia_demo" rel="noopener nofollow ugc">here</a> and the demo app is running at <a href="https://exinertia-demo.skyturtle.io" rel="noopener nofollow ugc">https://exinertia-demo.skyturtle.io</a>. I just added a default layout and a couple links to show <code>prefetch</code>.Thanks again for making this toolkit. I hope the the feedback helps. Please let me know if there is anything else I can clarify.</p>
<p>Also, any chance you have any examples of using the typed <code>Routes</code> module in a full code example or how to get SSR working for <code>prod</code>? If not, no worries. Thanks again!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356052" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/exinertia-toolkit-for-phoenix-inertia-js-integration-with-bun-and-vite/69280/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-356052" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356052"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="356557" data-post-id="356557">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="RxAssim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/RxAssim/120/30704_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  RxAssim
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Amazing feedback!</p>
<p>I’ve added all the necessary changes in order for everything to work flawlessly in the backend.</p>
<p>Changes were made to both the installer and the templates.</p>
<p>Would be great if you can check again just to make sure <img src="https://forum.elixirforum.com/images/emoji/apple/innocent.png?v=15" title=":innocent:" class="emoji" alt=":innocent:" loading="lazy" width="20" height="20"></p>
<p>Cheers!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356557" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/exinertia-toolkit-for-phoenix-inertia-js-integration-with-bun-and-vite/69280/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-356557" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356557"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="357090" data-post-id="357090">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="skyturtle" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/skyturtle/120/21845_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  skyturtle
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hey! I ran the ExInertia Igniter setup on a fresh Phoenix v1.7.20 install. There was a couple small hiccups, but fairly easy fixes. It looks like everything you did with <code>config_env()</code> and <code>def_env()</code> worked out. However, I did see there was a change to the <code>vite.config.ts</code> in the React template, which was causing an error where the manifest file could not be found:</p>
<pre data-code-wrap="shell"><code class="lang-shell">[error] Could not find static manifest at "/app/lib/ex_new_demo-0.1.0/priv/static/assets/vite_manifest.json". Run "mix phx.digest" after building your static files or remove the configuration from "config/prod.exs".
</code></pre>
<p>I deployed a demo app again with the changes below on a VPS and everything was working. I think <code>mix igniter.install exinertia</code> should work right away for dev and production if you incorporate the following changes:</p>
<ul>
<li>Revert to the output directory and filenames you had previously in <code>assets/vite.config.ts</code>:</li>
</ul>
<p>Reason: When <code>/assets/</code> was not there, the <code>vite_manifest.json</code> could not be found. Additionally, since you are changing the <code>outDir</code>, prepending <code>assets/</code> creates another subfolder which is not necessary, e.g. <code>priv/static/assets/assets/inertia.hash.js</code>.</p>
<pre data-code-wrap="diff"><code class="lang-diff">- outDir: "../priv/static",
+ outDir: "../priv/static/assets/",
</code></pre>
<pre data-code-wrap="diff"><code class="lang-diff">- entryFileNames: "assets/[name].[hash].js",
- chunkFileNames: "assets/[name].[hash].js",
- assetFileNames: "assets/[name].[hash][extname]",
+ entryFileNames: "[name].[hash].js",
+ chunkFileNames: "[name].[hash].js",
+ assetFileNames: "[name].[hash][extname]",
</code></pre>
<ul>
<li>In the layout templates, use string interpolation to prepend <code>/assets/</code> in the <code>src</code> attribute in the <code>&lt;script&gt;</code> tags for <code>app.js</code> and <code>inertia.js</code></li>
</ul>
<p>Reason: When the changes above for the <code>vite.config.js</code> are made, the assets are built correctly. Without having <code>/assets/</code>, the <code>src</code> attribute points to <code>priv/static/</code> and  <code>*.js</code> files are not found as that folder only has other digested static files like <code>robots.txt</code>,  <code>favicon.ico</code>, etc. By having <code>/assets/</code>, the <code>src</code> attribute will point to <code>priv/static/assets</code> where all the <code>*.js</code>, <code>*.tsx</code>, etc file have been built and hashed by Vite.</p>
<p><code>root.html.heex</code>:</p>
<pre data-code-wrap="diff"><code class="lang-diff">- src={Vite.Manifest.main_js()}
+ src={"/assets/#{Vite.Manifest.main_js()}"}
</code></pre>
<p><code>inertia_root.html.heex</code>:</p>
<pre data-code-wrap="diff"><code class="lang-diff">- src={Vite.Manifest.inertia_js()}
+ src={"/assets/#{Vite.Manifest.inertia_js()}"}
</code></pre>
<p>Hope that helps!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="357090" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/exinertia-toolkit-for-phoenix-inertia-js-integration-with-bun-and-vite/69280/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-357090" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="357090"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>