Home > Mobile >  How do I configure my default Vue application?
How do I configure my default Vue application?

Time:01-01

I have this automatically created Vue application which is created from a command and is all linked together, but for some reason it is not appearing in my browser. Here are the sources:

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vite App</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="application/octet-stream" src="src\main.js"></script>
  </body>
</html>

main.js

import { createApp } from 'c:/Users/kmba2/Coding/JavaScript/Tutorials/Vue Framework Tutorial/node_modules/vue/dist/vue'
import App from './App.vue'
import './assets/main.css'

const app = createApp(App)
app.mount('#app')

App.vue

<script type="module" setup>
import HelloWorld from './components/HelloWorld.vue'
import TheWelcome from './components/TheWelcome.vue'
</script>

<template>
  <header>
    <img alt="Vue logo"  src="./assets/logo.svg" width="125" height="125" />

    <div >
      <HelloWorld msg="You did it!" />
    </div>
  </header>

  <main>
    <TheWelcome />
  </main>
</template>

<style scoped>
header {
  line-height: 1.5;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }
}
</style>

I was expecting to see a stylized "Hello World" on my browser or the sources for the code. Instead I got errors in the console saying:

  • Not allowed to load local resource: file:///C:/Users/kmba2/Coding/JavaScript/Tutorials/Vue Framework Tutorial/node_modules/vue/dist/vue
  • App.vue:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.
  • main.css:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/css". Strict MIME type checking is enforced for module scripts per HTML spec.

CodePudding user response:

I found the answer to my query. I had some how managed to not complete the official steps for the template Vue (I deleted my default template and ran npm create vue@latest again, this time following and understanding the follow-up commandss) and my Node.js was not up to date. Instead of using the live server extension, I should have used the npm run dev command which was included in the setup for the the default template Vue application. See:

  • Related