0

Can someone explain the WHY of how Import Vue from 'vue' breaks the rendering of the template? I've seen other answers on how to work around this, but none of them have gone into the details of why it breaks.

I ran npm init and npm install vue, not using the CLI.

I created an index.html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>

    <script type="text/javascript" src="node_modules/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <first-task></first-task>
        {{msg}}
    </div>
    <script src="app.js"></script>
</body>
</html>

and an app.js looking like:

import Vue from 'vue/dist/vue.js'; //Remove to fix

Vue.component('first-task', {
  template: '<p>Hello World!</p>'
});

var app = new Vue({
    el: '#app',
    data: {
      msg: "Hello World"
    }
});

Removing the import, it renders fine, but it's unclear to me why this happens. My only guesses are that the default new Vue doesn't reference the full build, or that the implicit Render() doesn't get called, but I'm unsure of how to look into this more.

1 Answer 1

1

import statements may only appear in a javascript module

<script type="module" src="app.js"></script>

Should fix it, though you would not need to import Vue with your current code anyway, as you have seen

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.