Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIME type problem #478

Closed
collinsmarra opened this issue Jan 10, 2023 · 6 comments
Closed

MIME type problem #478

collinsmarra opened this issue Jan 10, 2023 · 6 comments
Labels

Comments

@collinsmarra
Copy link

I keep getting this error
image

So I am using trunk to serve a yew application. The point is to call M.AutoInit function from a materialize-css js library.
I have done my research and I notice that the web-server I am using is returning text/html instead of text/javascript
Is there a way I can configure trunk to help me with that?

#[wasm_bindgen(raw_module = "/materializejs/js/materialize.js")]
extern "C"{
    #[wasm_bindgen(js_namespace = ["M"])]

    type M;
    
    #[wasm_bindgen(static_method_of = M)]
    pub fn AutoInit();
}

pub fn auto_init_elements(){
    M::AutoInit();
}

#[function_component(Loader)]
pub fn load() -> Html{

    let div_ref = use_node_ref();
    {
        let div_ref = div_ref.clone();

        use_effect_with_deps(
            |div_ref|{
                let div = div_ref
                        .cast::<web_sys::HtmlElement>()
                        .expect("div_ref not attached to div element");
                let listener = Closure::<dyn Fn(Event)>::wrap(Box::new(|_|{
                    auto_init_elements();
                    // M::AutoInit();
                    // web_sys::console::log_1(&"clicked!".into());
                }));
                div.add_event_listener_with_callback(
                    "click",
                    listener.as_ref().unchecked_ref(),
                )
                .unwrap();

                move || {
                    div.remove_event_listener_with_callback(
                        "click",
                        listener.as_ref().unchecked_ref(),
                    ).unwrap()
                }

            },
            div_ref
        )
    }
        html!{
        <>
          <a id="dropdown2" class="dropdown-trigger btn" href="#" ref={div_ref} data-target="dropdown1">{"Drop Me!"}</a>
          <ul id="dropdown1"  class="dropdown-content">
                 <li><a href="#!">{"one"}</a></li>
                 <li><a href="#!">{"two"}</a></li>
                 <li class="divider" tabindex="-1"></li>
                 <li><a href="#!">{"three"}</a></li>
                 <li><a href="#!"><i class="material-icons">{"view_module"}</i>{"four"}</a></li>
                 <li><a href="#!"><i class="material-icons">{"cloud"}</i>{"five"}</a></li>
         </ul>
        </>
    }
}
@bluenote10
Copy link

I think I'm running into a similar issue with the trunk dev server. I'm simply trying to reference a basic styles.css from the index.html, but the browser rejects to apply it because the http response has the wrong MIME type:

image

image

@marc-mobeus
Copy link

I'm having the same issue

@ActuallyHappening
Copy link

Having very similar issue, chunk outputted by rollup that is not explicitly needed by wasm-bindgen is returned to the browser with the wrong MIME type:
image
image

Even though the file extension is .js

@ActuallyHappening
Copy link

Notice this comment: #198 (comment)
In my case, the file I was imagining to be my js chunk was actually the index.html, since wasm-bindgen didn't require that specific file it was not copied over to the server (/dist) and hence wasn't there to be served.

The MIME type shenanigans actually helped me this time, I can't treat HTML (actual and MIME type text/html) as a .js file!

If you searching through the networking logs for MIME types because the error says 'wrong mime type!', just take a peak at the actual data being send as well :)

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Sep 10, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants