4

I installed the following via Bower:

  • jQuery 3.1.0
  • Vue 1.0.26
  • Require.js 2.2.0

But when I load my site, "Vue" is undefined.

I tried var vue = require('Vue') and stuff, but it doesn't seem to work.

Vue says it is a AMD module and so is Require.js... What am I missing?

2
  • You are missing Require.js :) Commented Jul 11, 2016 at 8:31
  • 2
    var vue = require('Vue') is not Require.js syntax - it's CommonJS syntax, as used by nodejs on the server side, or build tools like browserify or webpack on the client side. You should read up on how requirejs and AMD modules actually work and weither it is what you want/need. Commented Jul 11, 2016 at 9:56

1 Answer 1

8

var vue = require('Vue') won't work by itself. Either you:

  1. Change it to the form of require that takes a callback:

    require(['Vue'], function (vue) {
      // code that uses Vue
    });
    
  2. Or put your require call in a define call:

    define(function (require) {
      var vue = require('Vue');
    });
    

As Linus Borg pointed out, require with a single string is CommonJS syntax, which RequireJS supports only if it appears in the callbacks passed to define. (See this.)

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.