imtiaz
Phoenix 1.5 include materialize-css using npm
Hi, I’m new to Phoenix. I’m using 1.5 to build a web application. I want to use materializecss.
I know I can directly copy the cdn urls and paste it to layout file. But I want to do it via npm.
So, I found this package materialize-css and installed it inside the assets folder using npm install materialize-css@next --save.
The problem I’m facing is, I included @import "~materialize-css/dist/css/materialize.min.css"; in my app.scss file. Also, added import "materialize-css/dist/js/materialize.min"; in my app.js file.
When I run mix phx.server it’s giving me error
ERROR in multi ./js/materialize.min.js
Module not found: Error: Can’t resolve ‘./js/materialize.min.js’ in ‘/Users/imtiaz/Etectra/work/recyclebin/assets’
@ multi ./js/materialize.min.js materialize[0]
Any idea how to resolve it?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 10 of 12 Posts
kokolegorille
Hello and welcome,
Try to change this to…
imtiaz
Thanks @kokolegorille. It doesn’t solve the problem. I guess it’s showing this because inside my
webpack.config.jsthere is a line:I removed the line with materialize and it removes the error. Not sure why I’m getting jquery is undefined.
I installed jquery via npm and added
inside webpack.config.js file’s plugin section.
Also, in
app.jsadded:Any idea? I know it’s a question inside another question, but I’m a newbie and getting issues every time
kokolegorille
It’s something I had to do for BS4, luckily now BS5 dropped jquery.
I try not to include jquery. JS has evolved enough not to need it anymore.
But when needed, I found some different solutions, one is to use splitChunks.
Nothing special in app.js (remove your code)
And modify layout like this.
The example is for bootstrap 4, so You can remove popper too.
Now I try to avoid css framework with jquery dependency.
Needless to say it’s a real pain
imtiaz
Seems like a real pain adding jquery. Now, everything fall apart.
materialize.min.jsgiving errors thatjQuery is not definedI guess, need to find a css framework without jquery dependency
kokolegorille
I tried materialize-css some years ago, but now I would try
or the lite version.
lbormann
Hi guys,
I can not figure out a working solution for Phoenix 1.5 (incl. Liveviews) + materializecss.
Webpack Version is 4.41.5.
A working result should achieve the following working:
Side-Nav-Materializecss
So that I can call:
$(".button-collapse").sideNav();at the bottom of template or via liveview-hooks.
In my tries to get a solution (alot of hours by now), I also face the “jquery ($ not found)” problem.
Is there someone out with a working solution?
Thanks so much for the help!
kokolegorille
How do You load jQuery?
It might not be available yet and You might need to use something like…
lbormann
I tried a modification in the default generated ‘app.js’ in previous tries:
window.addEventListener(“phx:page-loading-start”, info =>
{
topbar.show()
$(“.button-collapse”).sideNav()
})
Current state of Chrome-Console:
GET http://localhost:4005/js/vendor.js net::ERR_ABORTED 404 (Not Found)
kokolegorille
What happens when You type $ in devtools console?
What is this rc2Contentscript.js?
lbormann
What happens when You type $ in devtools console?
Returns:
What is this rc2Contentscript.js?
Good question, I guess its coming from webpack. It is not from my code:
After searching the web I found following regarding nextcloud:
https://github.com/nextcloud/forms/issues/842
My webpack-Config looks like that: