Javascript inclusion in Magento 2

Magento 2 - enable cash on delivery only for specific shipment method
How to implement a grid like Related Products in Magento?

I followed step by step this tutorial to include owl-carousel in Magento 2. http://www.boolfly.com/magento-2-slider-with-owl-carousel./
The problem is that I get this error:

VM29879:1 Uncaught SyntaxError: Unexpected token /

on this script

<script type="text/x-magento-init">// <![CDATA[
], function ($) {   
      $(document).ready(function () {
            navigation: true,
            items: 4
// ]]>

(somehow I cannot put everything here, but you can see the code in the article also).

Because of this error, requirejs doesn’t load my script.

If I remove type="text/x-magento-init" I don’t get the error, but still no js loaded, because it needs this type.

Does anyone had this problem or know how to solve it?

Related Posts

  • How do I remove jQuery Conflict in prototype.js with 1.11.1.jquery.min.js (3)
    I have a conflict between jQuery and another library. I added the code below to the local.xml file as per answers found here. <?xml version="1.0"?> <layout> <default> <reference name="head"> <action method="addJs" name="jquery" […]
  • How to call external code in Magento 2 (1)
    I am new to Magento. I need to include an external code into my store. <script src='https://cdn.rawgit.com/michalsnik/aos/2.0.4/dist/aos.js' src_type="url" /></script> I have included this above into […]
  • Magento2 requirejs inclusion (1)
    From what I've read there are 2 ways to include your javascript files: 1) In catalog_product_view.xml you insert <link src="js/product.js"/> and in web/js/product.js you add your js code specific to the product page (old magento1 way). 2) The second way (the way magento2 […]
  • Format price with javascript in Magento 2 (2)
    In javascript I have calculated a number. Which I want to display as a price. My JS file define([ 'jquery' ], function ($) { "use strict"; function irreleventCalculations() { // black magic here return 19.949999; } var price = […]
  • Magento2: Lots of JS Errors on 2. -> Page Load (0)
    Hi Fellow Magento Users! I have a little problem with loading Javascripts.On first pageload after a cleanup of files and upgrade:setup i experience a page that loads javascripts really slow, and there is a lot of them, but absolutely no errors.however on second load javascripts is […]
  • dealing with cache (2)
    I'm developing couple of Magento extensions that change the content of the sites dynamically (alternative products sorting, different related items, etc), based on things like user and time. These features work perfectly on non cached sites, but unfortunately for most sites there's […]
  • Question to expect for a front end magento position (1)
    I have interview coming up and it will be a interview for magento first time,i search SE and i could find one question, but it was for developer. I been working online for magento project but this time i am nervous and want to get the job, so gotta have a good interview. So as a […]
  • Magento 2: Adding external CSS and JS to only one content page, and use jquery functions inside the content (1)
    I am trying to add some dynamic function to one content page of a Magento 2 site, but didn't manage to do it. Here is what I thought: 1) Adding the external javascript files at the "Layout Update XML" under "design": <head> <css src="https://xxxxxx.com/xxxx/css/abc.css" […]
  • Failed to load css and js script after successful installation (2)
    I have got a hard time dealing with the Magento installation. The installation is successful but the page is showing just plain text with all css and javascript failed to load. I am using subdomain of shop.domain.com to point to a subfolder in my root. My root domain.com is a […]
  • Get Product attribute to Javascript (1)
    I'm making and slide in function to that product page. So when you are close to the bottom a static block will come visible. That static block should have a link to an article the link is different from product to product and is set in by a custom product attribute. The problem […]
Magento 2 - enable cash on delivery only for specific shipment method
How to implement a grid like Related Products in Magento?

2 Comments on this article

  • User November 12, 2016

    You can replace your requiejs-config.js file with below code,

    var config = {
        paths: {            
                'owlcarousel': "js/owl-carousel/owl.carousel"
        shim: {
            'owlcarousel': {
                deps: ['jquery']

    after apply code press below command,

    php bin/magento setup:static-content:deploy



  • User November 12, 2016

    You definitely do not need use “text/x-magento-init for you script. It’s used only for declarative component initializing and use json format.


Add a comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax