3

I followed Smooch instructions with no success.

Here is the minimal code that fails for me:

<!doctype html><html>
<head>
    <meta charset="utf-8">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"></script>
    <script>
        require.config({
            "paths": {
                "smooch": "https://cdn.smooch.io/smooch.min"
            }
        });
        // Tried this
        require(["require", "smooch"], function(require){
            var Smooch = require("smooch");
            console.log(Smooch);  // → undefined
        });
        // Tried that
        require(["smooch"], function(Smooch){
            console.log(Smooch);  // → undefined
        });
    </script>
</head>
<body></body>
</html>

require returns me an undefined so no Smooch.init(...) for me. Tested in both Firefox and Chrome.

Am I doing something wrong ?

Maxime R.
  • 9,621
  • 7
  • 53
  • 59

1 Answers1

3

You should use "Smooch" instead of "smooch" in your require calls, like this :

<!doctype html><html>
<head>
    <meta charset="utf-8">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"></script>
    <script>
        require.config({
            "paths": {
                "Smooch": "https://cdn.smooch.io/smooch.min"
            }
        });
        // Tried this
        require(["require", "Smooch"], function(require){
            var Smooch = require("Smooch");
            console.log(Smooch);  // → Smooch object
        });
        // Tried that
        require(["Smooch"], function(Smooch){
            console.log(Smooch);  // → Smooch object
        });
    </script>
</head>
<body></body>
</html>

The lib is wrapped in a UMD wrapper and self-defines its name to be "Smooch".

  • Thanks a lot, indeed it fixed the issue. I think I had tried `Smooch` instead of `smooch` but I must have had something else broken at that point and then reverted to what the readme said. – Maxime R. Apr 22 '16 at 15:35
  • 1
    No problem! We will update the documentation to explain this better. – Marc-Antoine Lemieux Apr 22 '16 at 17:05