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

After using vue-router, there is an error in packaging and running # Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec. #863

Closed
reaink opened this issue Sep 28, 2020 · 8 comments

Comments

@reaink
Copy link

reaink commented Sep 28, 2020

#93 Describe the bug

After using vue-router and build, there will be errors when and run in nginx.

image
image

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

Tried Nginx to add type information to js files but the same error still occurs

System Info

  • required vite version: 1.0.0-rc.4
  • required Operating System: Linux
  • required Node version:v12.16.3
  • Optional:
    • npm/yarn version 6.14.4
    • Installed vue version (from yarn.lock or package-lock.json) 3.0.0
    • Installed @vue/compiler-sfc version 3.0.0
@reaink
Copy link
Author

reaink commented Sep 29, 2020

Visiting any .vue page will correspond to index.html

image

@underfin
Copy link
Member

Can you give a reproduction? It looked very weird.This should hasn't Home.vue request after build.

@reaink
Copy link
Author

reaink commented Sep 29, 2020

@underfin

I found the problem

Encapsulating defineAsyncComponent as a function will cause the component to not be read, so there is no abnormality when developing, but the vue file will not be packaged when packaging

The error is

function loadView(view) {
  return defineAsyncComponent(() => import(`../views/${view}.vue`));
}

routes: [
    {
      path: "/",
      name: "Home",
      component: loadView('Home')
    }
]

This will cause the corresponding vue file to not be packaged when packaging

@reaink
Copy link
Author

reaink commented Sep 29, 2020

@underfin Thank you!

@reaink reaink closed this as completed Sep 29, 2020
@MatthiasGrandl
Copy link

@nshusr hey can you tell me how you solved this? Does defineAsyncComponent work at all for you? I don't have it encapsulated in a function like in your example and I get the same error.

@MatthiasGrandl
Copy link

Oh nevermind, I guess a loop around it causes the same problem.

@reaink
Copy link
Author

reaink commented Nov 2, 2020

@MatthiasGrandl

Write each route import separately and it will work fine

It seems that the imported components cannot be written as functions yet

can use

routes: [
    {
      path: "/",
      name: "Home",
      component: defineAsyncComponent(() => import('../views/Home.vue'));
    },
    {
      path: "/about",
      name: "About",
      component: defineAsyncComponent(() => import('../views/About.vue'));
    }
]

@MatthiasGrandl
Copy link

@nshusr yeah figured it out. thanks though!

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants