lmletham

lmletham

Adding nodejs package to my Phoenix project broke esbuild. How to fix it?

Hey guys!

I added a JS package to my Phoenix project, specifically TipTap so I could have a text editor. They did not have Phoenix Framework specific install instructions so I used the Vanilla JS instructions and it seems to have worked locally but whenever I try to run fly deploy I get build errors now.

I have checked the following:

I assume that my issue is some kind of relative path problem? I’m just not pointing correctly to the node_modules folder? But this is my folder structure and I don’t see anything wrong with the relative paths I have.

If anyone could help point out what the trouble spot is here, I’d greatly appreciate it!

P.S. I forgot to add, I also tried:

  • using a relative path to the node_modules folder in the app.js import. That didn’t work.
  • marking the path as external (as suggested by the error message) but I must not have done it right because that also didn’t fix anything.

Marked As Solved

lmletham

lmletham

OK. I got it working now. I also posted this question to r/elixir and got a suggestion there:

If you are using most other default configuration, you’ll want to have your node_modules directory (along with the package.json etc.), inside of the assets folder.

So I moved package.json, package-lock.json, and the node_modules folder into my assets folder. That seems to have fixed things. The fly deploy ran successfully.

That poster also pointed out the documentation which I had read, but not clearly understood. It looks like there is a line there in option 2 that says “Call npm inside your assets directory”. I didn’t think that was the option I was using, but it looks like I should have used npm install from the get-go from inside that directory and it would have created the node_modules folder where it needed to go.

I also left in the changes that @dfalling suggested, so I’m not sure if that is part of why things are working now, but I’m glad they are. Thanks again everyone.

Also Liked

D4no0

D4no0

have you checked if you have the dependency in package.json? the folder node_modules usually is added in gitignore.

dfalling

dfalling

When I migrated to Fly.io, I had to tweak my project a bit to install NPM packages.

I think this is all I had to patch:

Add npm and nodejs here in Dockerfile:

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git nodejs npm \
    && apt-get clean && rm -f /var/lib/apt/lists/*_*

Add an npm ci install step to mix.exs assets.deploy:

      "assets.deploy": [
        "cmd --cd assets npm ci",
        "tailwind default --minify",
        "esbuild default --minify",
        "phx.digest"
      ],

Let me know if this doesn’t work- I may have missed another step I’m not remembering now.

dfalling

dfalling

One other note: I just learned that npm ci actually installs dev dependencies as well. I’ve updated my build to this:

npm ci --only=prod

This ensures dev dependencies (eg rollup, prettier, etc.) aren’t included in the prod build.

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
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
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement