The Cal.com vanilla javascript integration does not function properly when used with Svelte

I have been trying to integrate cal.com into a SvelteKit website, but I am facing difficulties implementing it using vanilla JavaScript as per the official documentation.

While following the instructions provided for vanilla JavaScript, I had success with the version for Next.js, but I seem to be encountering issues with Svelte.

The last line Cal("init") is causing an error stating "Cannot find name 'Cal'." Additionally, when checked on the server, it shows a "500 Internal Error."


<script>
  (function (C, A, L) {
    let p = function (a, ar) {
      a.q.push(ar);
    };
    let d = C.document;
    C.Cal =
      C.Cal ||
      function () {
        let cal = C.Cal;
        let ar = arguments;
        if (!cal.loaded) {
          cal.ns = {};
          cal.q = cal.q || [];
          d.head.appendChild(d.createElement("script")).src = A;
          cal.loaded = true;
        }
        if (ar[0] === L) {
          const api = function () {
            p(api, arguments);
          };
          const namespace = ar[1];
          api.q = api.q || [];
          typeof namespace === "string" ? (cal.ns[namespace] = api) && p(api, ar) : p(cal, ar);
          return;
        }
        p(cal, ar);
      };
    })(window, "https://cal.com/embed.js", "init");
    Cal("init")
  </script>

Answer №1

After some trial and error, I discovered that pasting the script into the +page.svelte file was not working. To get it to function properly, you actually need to insert it within the head tag in the app.html file.

Answer №2

It may be a bit late, but loading the app.html unnecessarily is not ideal. To keep that code within a specific component, try placing it inside the onMount function.

In some cases, Svelte or SvelteKit may highlight the error you encountered due to linting. Simply add // @ts-nocheck and the issue should resolve. I was able to fix mine by using that method.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Verify whether a specific value is present within a nested array in MongoDB

Looking to verify whether a value sent in a request already exists within an array associated with a particular User. The data structure is as follows: { "_id": "63233972df0f14076e027106", "firstName": "mako" ...

Transferring an Object from one AngularJS Controller to Another

Currently delving into the world of AngularJS, I've encountered a seemingly trivial problem with no solution in sight. My issue lies in managing two lists/controllers created by a factory service. Specifically, I'm facing difficulties removing ...

React Alert: Unable to update state in an unmounted React component

I have encountered an issue while using Redux in this particular file. When I click on the second component, I receive the following error message: Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it ind ...

Combining the power of Node.js and Node-MySQL with Express 4 and the versatile Mustache

Currently, I am delving into the world of Node.js and encountering a bit of a roadblock. My focus is on passing a query to Mustache. Index.js // Incorporate Express Framework var express = require('express'); // Integrate Mustache Template En ...

Error code 10062 occurred on the Discord Bot while verifying the channel name during the processing of a user-sent slash command

I've been developing a Discord bot using JavaScript for a study server with my friends. Currently, I'm working on a feature that allows users to add phone numbers but only in specific channels. Everything was functioning properly until I implemen ...

What is the significance of using index 0 for caching an ID in jquery?

What is the reason behind using an index of 0 in the following code? var $one = $('#one')[0]; Is there a specific purpose for not just using var $one = $('#one'); ? SOURCE I came across the above code while researching about jQuery, ...

When JSON.stringify is used to convert an object to JSON, it will result in

I'm having difficulty creating a JSON object for transmission over the network. The particular array I'm dealing with looks like this in the Chrome debugger. event: Array[0] $$hashKey: "02Q" bolFromDB: 1 bolIndoor: null ...

Troubleshooting: Issues with Jquery's replaceWith function

I'm facing an issue with a table I have that includes a button in one of its columns. The button is supposed to toggle the class of the current row in the table and then replace itself once clicked. $(document).ready(function() { $(".checkOut"). ...

Slick carousel not functioning properly with Angular slickGoTo

I am currently working with the angular-slick-carousel library. Unfortunately, I am encountering an issue where the Slick methods, such as slickGoTo(), are not functioning as expected. Below is my Controller setup following the provided documentation: $s ...

Exploring the Interaction Between Node.js and a Windows 10 Server on a Local Machine

I am curious about the interaction between Nodejs Server and a local machine. Specifically, I would like to understand how tasks such as: Thread Level CPU Cycle Socket Level IO Any help in clarifying this process would be greatly appreciated. ...

Bcrypt.compare failing to match the passwords

I implemented a bcrypt.compare function in my code, but I'm running into an issue where it seems to not be comparing the passwords correctly. Regardless of the input password, the function always returns a status of ok. Can someone take a look at the ...

Encountering a problem while creating a Page Object in webdriver.io - getting the error "setValue is not a function" or "cannot read property 'setValue' of undefined"

While working on a webdriver.io automation project, I encountered an issue with recognizing objects in my page object file (login.po.js) when calling them in the test spec file (test.spec.js). The error message displayed is LoginPage.username.setValue is n ...

Am I incorrectly linking Javascript/CSS files/pages?

<script src="scripts/lib/angular.min.js"></script> <script src="scripts/lib/angular-route.min.js"></script> <script src="scripts/lib/angular-animate.min.js"></script> <script src="scripts/lib/jquery.min.js"></sc ...

Assignments made to the 'toLoadNumber' variable within the React Hook useEffect will be reset after every re-render

I encountered an issue in the console related to the code snippet below: export const Contact = () => { useEffect(() => { // Code inside this block runs when the component mounts. return () => { // Code inside this block runs when the component ...

Switching styles in AngularJS without using ng-class

My goal is to allow users to switch the class from incomplete to complete when they click a button and the function(response) returns 1. I have attempted to use ng-class, but it is not effective because the HTML elements are generated with a PHP loop. This ...

I am unsure about implementing the life cycle in Svelte.js

Unknown Territory I am not well-versed in front-end development. Desire to Achieve I aim to utilize the lifecycle method with SvelteJS. Error Alert An error has occurred and the lifecycle method is inaccessible: ERROR in ./node_modules/svelte/index.m ...

Using the .splice() method in Javascript to eliminate elements from an array

I am currently working on a function that loops through an array and eliminates any elements that are false, null, 0, undefined, NaN, or an empty string. Instead of returning an empty array as expected, the current output is [null,0,null,null,""]. Below i ...

The icon is being displayed as text instead of the actual Fontawesome icon

Using jquery version 3.3.1 I am dynamically creating an anchor tag: let link = $("<a>"); link.attr("href", "#"); link.text("My anchor" + ' <i class="fas fa-people-carry"></i>'); However, when I try to display ...

What is the process of transforming async/await code into synchronous code in JavaScript?

Blocking the event loop is generally considered bad practice due to its consequences. However, even the native fs module includes some synchronous functions for specific purposes, such as CLIs using fs.readFileSync. I am interested in converting the follo ...

Error: SyntaxError - Found an unexpected token ":"

Can someone help me with this unexpected token : error that I am encountering? Here is the code where the issue is happening. <script type="text/javascript> $('.delete-btn').click(function() { $.ajax(function() { type: 'POST&apo ...