Uncaught SyntaxError: The requested module ‘https://cdn.skypack.dev/marked’ does not provide an export named ‘marked’

Hello everyone I’m trying to solve the challange of freeCodeCamp markdown previewer but I got Uncaught SyntaxError: The requested module ‘https://cdn.skypack.dev/marked’ does not provide an export named ‘marked’ and in the display I cannot see the editor. What is wrong with that?

I tried to solve th
e problem with some tutorial but didn’t help.

FontAwesome is breaking Events on elements

here is my HTML

<td data-label="Handle" class="server-handle-options noselect">
    <i class="server-control-item fa-solid fa-play" api-action="START"></i>
    <i class="server-control-item fa-solid fa-arrows-rotate" api-action="RESTART"></i>
    <i class="server-control-item fa-solid fa-stop" api-action="STOP"></i>
</td>

My issue is that my code:

// First element of the controls
var controlItems = entryHeadline.querySelector('.server-control-item');
controlItems.addEventListener('click', function () {
    console.log("heyyy");
});

Isnt firing when clicking on the server control Item, it was working before because i was using Jquery:

$("#server-list").on('click', '.server-control-item', function () {   [. . .]   });

Was working, probably because thoses both methods work differently

Here is what the Html looks like in the DOM after the page is fully loaded

<td data-label="Handle" class="server-handle-options noselect">
        <svg class="svg-inline--fa fa-play server-control-item" api-action="START" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="play" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" data-fa-i2svg=""><path fill="currentColor" d="M73 39c-14.8-9.1-33.4-9.4-48.5-.9S0 62.6 0 80V432c0 17.4 9.4 33.4 24.5 41.9s33.7 8.1 48.5-.9L361 297c14.3-8.7 23-24.2 23-41s-8.7-32.2-23-41L73 39z"></path></svg><!-- <i class="server-control-item fa-solid fa-play" api-action="START"></i> Font Awesome fontawesome.com -->
        <svg class="svg-inline--fa fa-arrows-rotate server-control-item" api-action="RESTART" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="arrows-rotate" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M89.1 202.6c7.7-21.8 20.2-42.3 37.8-59.8c62.5-62.5 163.8-62.5 226.3 0L370.3 160H320c-17.7 0-32 14.3-32 32s14.3 32 32 32H447.5c0 0 0 0 0 0h.4c17.7 0 32-14.3 32-32V64c0-17.7-14.3-32-32-32s-32 14.3-32 32v51.2L398.4 97.6c-87.5-87.5-229.3-87.5-316.8 0C57.2 122 39.6 150.7 28.8 181.4c-5.9 16.7 2.9 34.9 19.5 40.8s34.9-2.9 40.8-19.5zM23 289.3c-5 1.5-9.8 4.2-13.7 8.2c-4 4-6.7 8.8-8.1 14c-.3 1.2-.6 2.5-.8 3.8c-.3 1.7-.4 3.4-.4 5.1V448c0 17.7 14.3 32 32 32s32-14.3 32-32V396.9l17.6 17.5 0 0c87.5 87.4 229.3 87.4 316.7 0c24.4-24.4 42.1-53.1 52.9-83.7c5.9-16.7-2.9-34.9-19.5-40.8s-34.9 2.9-40.8 19.5c-7.7 21.8-20.2 42.3-37.8 59.8c-62.5 62.5-163.8 62.5-226.3 0l-.1-.1L109.6 352H160c17.7 0 32-14.3 32-32s-14.3-32-32-32H32.4c-1.6 0-3.2 .1-4.8 .3s-3.1 .5-4.6 1z"></path></svg><!-- <i class="server-control-item fa-solid fa-arrows-rotate" api-action="RESTART"></i> Font Awesome fontawesome.com -->
        <svg class="svg-inline--fa fa-stop server-control-item" api-action="STOP" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="stop" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" data-fa-i2svg=""><path fill="currentColor" d="M0 128C0 92.7 28.7 64 64 64H320c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128z"></path></svg><!-- <i class="server-control-item fa-solid fa-stop" api-action="STOP"></i> Font Awesome fontawesome.com -->
    </td>

By logic, it means that FontAwesome make some alteration in the DOM object making my Event Break, what would be the solutions ?

Reading .pkl file from S3 bucket using lambda function for data visualisation

I want to host my ML model(.pkl file) on AWS. For this I have uploaded the .pkl in S3 Bucket. Now I want to write a lambda function in JS that will call the model to generate predictions for visualisation. The lambda function will be trigerred when user give input values from frontend.

I wrote this Lambda Function but getting errors with the imports in AWS Lambda. Also tried while commenting them out but no success. What should be done?

//import * as AWS from 'aws-sdk';
//import S3 from 'aws-sdk/clients/s3';
//import * as sklearn from 'scikit-learn';


const s3 = new S3();
const bucketName = 'epl-pkl';
const objectKey = 'epl.pkl';

async function loadModelFromS3() {
  const params = {
    Bucket: bucketName,
    Key: objectKey,
  };
  const modelObject = await s3.getObject(params).promise();
  const modelBuffer = Buffer.from(modelObject.Body.toString(), 'base64');
  const loadedModel = sklearn.load(modelBuffer);

  return loadedModel;
}


async function makePredictions(inputData) {
  const loadedModel = await loadModelFromS3();
  const predictions = loadedModel.predict(inputData);
  return predictions;
}



export async function handler(event) {
  const inputData = event.data; 
  const predictions = await makePredictions(inputData);
  return {
    statusCode: 200,
    body: JSON.stringify(predictions),
  };
}

Problems with making background

I’m working on this project but I would like for the background to be also around the profile div. this is it

this is the HTML

<div class="content">
            <div class="profile">
                <h4>Jay</h4>
                <img src="default.jpg" width="125">
            </div>
            <div class="content">
                <h2>Test</h2>
                <p>hello guys hehe</p>
            </div>
</div>

and this is the CSS

.content{
    background-color: rgb(200, 200, 200);
    padding: 10px;
}

.profile{
    background-color: rgb(180, 180, 180);
    padding-left: 10px;
    padding-right: 10px;
    padding-bottom: 5px;
    float: left;
    text-align: center;
    margin-right: 10px;
}

Sorry if I explained it badly. English isn’t my first language.

I tried looking it up on internet but I couldn’t find it. It was most likely due my poor describing skills.

.content {
  background-color: rgb(200, 200, 200);
  padding: 10px;
}

.profile {
  background-color: rgb(180, 180, 180);
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 5px;
  float: left;
  text-align: center;
  margin-right: 10px;
}
<div class="content">
  <div class="profile">
    <h4>Jay</h4>
    <img src="default.jpg" width="125">
  </div>
  <div class="content">
    <h2>Test</h2>
    <p>hello guys hehe</p>
  </div>
</div>

How do I display the current speed of a user using javascript

Need help displaying current speed in my code using Javascript. It seems like it relies on a certain Javascript code to display when it’s not supposed to. The current speed is either not showing or is delayed. Suggestions

I’ve tried using chatgpt although it does not help. The us play of the current speed still obtained from the Javascript doesn’t display

Trying to find a way to emulate a hover design I saw on Pinterest

On pinterest, when you hover an image, it darkens and shows some details of the poster. But when you move the cursor away from the image, this hover effect seems to stay for a very short period. When you move your cursor over many images, it even creates a small trail of darkened images due to this delay. However, there seems to be no delay or transition for when the hover effect starts.

Can this be done in CSS? I’m not sure how to delay just the exit of a hover animation.

I’m pretty new to web dev, hope the description makes sense! 🙂

how to replace some text with special character?

I want to highlight some sentences in a text and I created this function:

       function highlightReviewAux(content,text) {
            return content.replace(new RegExp(`\b${text}\b`, "gi"), match => {
                return '<span class="highlightText">' + match + '</span>';
            });

It works except for this content “. […] I booked this for a very special occasion, trusting that (the current title( “5 star The best 1 bed in Shoreditch” “

I think it’s for the special characters.
This is the error:

SyntaxError: Invalid regular expression: /bNice wooden Bedroom floor showed poor care when decorating as white paint splatted all over it. [...] I booked this for a very special occasion, trusting that (the current title( “5 star The best 1 bed in Shoreditch” b/: Unterminated group

Can you help me? I’m here for more than 2 hours and can’t find the solution…

Problem with getting data using XMLHttpRequest

I have problem with getting data from server (computer on other network) using XMLHttpRequest. If I type URL directly in browser it shows json text, but not this way.

The code is:

document.getElementById("getMessage").onclick = function () {
          const req = new XMLHttpRequest();
          req.open(
            "GET",
            "https://mytest.com",
            true
          );
          req.send();
          req.onload = function () {
            const json = JSON.parse(req.responseText);
            document.getElementsByClassName("message")[0].innerHTML =
              JSON.stringify(json)

Don’t understand this is server problem or code problem. Because this code works fine with free APIs like, for instance, “https://open-meteo.com/”.

Sort table, but ignore line breaks and previous spaces

I am using the current JavaScript code to sort text in tables, however sometimes the html editor adds line breaks for long lines, and when the word in the code starts in a new line, the sorting doesn’t work properly (column 2 in the example)

How can the JS code be fixed to work around such issue?

The current working code:

window.onload = function() {
  document.querySelectorAll('th').forEach((element) => { // Table headers
    element.addEventListener('click', function() {
      let table = this.closest('table');

      // If the column is sortable
      if (this.querySelector('span')) {
        let order_icon = this.querySelector('span');
        let order = encodeURI(order_icon.innerHTML).includes('%E2%86%91') ? 'desc' : 'asc';
        let separator = '-----'; // Separate the value of it's index, so data keeps intact

        let value_list = {}; // <tr> Object
        let obj_key = []; // Values of selected column

        let string_count = 0;
        let number_count = 0;

        // <tbody> rows
        table.querySelectorAll('tbody tr').forEach((line, index_line) => {
          // Value of each field
          let key = line.children[element.cellIndex].textContent.toUpperCase();

          // Check if value is date, numeric or string
          if (line.children[element.cellIndex].hasAttribute('data-timestamp')) {
            // if value is date, we store it's timestamp, so we can sort like a number
            key = line.children[element.cellIndex].getAttribute('data-timestamp');
          } else if (key.replace('-', '').match(/^[0-9,.]*$/g)) {
            number_count++;
          } else {
            string_count++;
          }

          value_list[key + separator + index_line] = line.outerHTML.replace(/(t)|(n)/g, ''); // Adding <tr> to object
          obj_key.push(key + separator + index_line);
        });
        if (string_count === 0) { // If all values are numeric
          obj_key.sort(function(a, b) {
            return a.split(separator)[0] - b.split(separator)[0];
          });
        } else {
          obj_key.sort();
        }

        if (order === 'desc') {
          obj_key.reverse();
          order_icon.innerHTML = '&darr;';
        } else {
          order_icon.innerHTML = '&uarr;';
        }

        let html = '';
        obj_key.forEach(function(chave) {
          html += value_list[chave];
        });
        table.getElementsByTagName('tbody')[0].innerHTML = html;
      }
    });
  });
}
<div align="center">
  <table border="1">
    <thead>
      <tr class="header">
        <th>Title <span>&uarr;</span></th>
        <th>Title2 <span>&uarr;</span></th>
      </tr>
    </thead>
    <tr>
      <td>text</td>
      <td>ear</td>
    </tr>
    <tr>
      <td>arabic</td>
      <td>
        cat</td>
    </tr>
    <tr>
      <td>words</td>
      <td>
        dark</td>
    </tr>
    <tr>
      <td>here</td>
      <td>black</td>
    </tr>
  </table>
</div>

Firebase Firestore v9 with React Native and Expo – addDoc stop working: [TypeError: undefined is not a function]

Recently I upgraded to expo sdk 48, and with doing that firebase got updated to @9.18.0,
Everthing working fine except when i tried to add a new documnet using addDoc (all over my app, i use the addDoc in aproximately 15 screens)
(I also had a minor issue with getAuth due to asyncStorage incompability which i manage to resolve temporarily)

This is my firebase.js configuration:

import { initializeApp, getApps, getApp } from "firebase/app";
// import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
import { getStorage } from "firebase/storage";
import { getDatabase } from "firebase/database";

import AsyncStorage from "@react-native-async-storage/async-storage";
import { getReactNativePersistence, initializeAuth } from "firebase/auth/react-native";


const firebaseConfig = {}


let app;
if (getApps().length === 0) {
    app = initializeApp(firebaseConfig);
} else {
    app = getApp();
}

// const auth = getAuth(app);
const auth = initializeAuth(app, { persistence: getReactNativePersistence(AsyncStorage) }); // temporary solution instead of getAuth for the expo sdk 48 after removing asyncstroage deprecated version
const db = getFirestore(app);
const storage = getStorage(app);
const realtimeDB= getDatabase(app);

export { db, auth, storage, realtimeDB};

and here is a simplified example of one place that I’m using the addDoc function:

import { storage, db, auth } from "../firebase";
import { collection, doc, addDoc, serverTimestamp, setDoc } from "firebase/firestore";

const sendMessage = async (data) => {
    payload = {
        type: data.type,
        userId: data.userId,
        userName: data.userName,
        body: data.body,
        timestamp: serverTimestamp(),
    };

    const collRef = collection(db, "chats", data.chatId, "messages");
    let messageId = "first_message";
    try {
        const docRes = await addDoc(collRef, payload);
        messageId = docRes.id;
    } catch (error) {
        console.log("addDoc Error: ", error);
        try {
            await setDoc(doc(collRef, messageId), payload);
        } catch (error) {
            console.log("Failed of creating new message in Chats: ", error);
        }
    }
};

When running this code, the addDoc get skipped and setDoc is kick in and get exceuted,
this is the log i get in the console after calling sendMessage function:

LOG addDoc Error: [TypeError: undefined is not a function]

Please i really need any help with this.
thank you kind people.

I tried, of course downgrading expo sdk back to 47, and firebase to 9.17.0,
and nothing was changed, I also tried to remove node_moduls and reinstall them which did nothing.

I also tried asking my friend chatGPT, which have no clue LOL.

How to remove broken images coming via api?

I am writing a project in which I receive data from the server about different films, but in one of the genres a huge number of pictures are broken and it does not come out beautifully.

An example to understand what it looks like:
enter image description here

I need to remove broken pictures from the film’s row. I tried to fix it using the error handler – onError:

 const [showImage, setShowImage] = React.useState(true);

  const hideImg = (e: any) => {
    setShowImage(false);
  };
  
      <div>
        {showImage ? (
          <img
            src={`https://image.tmdb.org/t/p/w500/${item?.backdrop_path}`}
            alt={item?.title}
            onError={hideImg}
          />
        ) : null}
      </div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

As a result, broken images still take up space and this is not what I need…
Result:
enter image description here

I get data from the server like this:

React.useEffect(() => {
    try {
      axios.get(fetchURL).then((res) => {
        setMovies(res.data.results);
      });
    } catch (e) {
      console.error("Error>", e);
    }
  }, [fetchURL]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

Maybe it’s possible to catch broken images in a try/catch block and remove them? I will be grateful for the answer

Cloudinary resources taking too long to fetch on NextJS app deployed in Google Cloud Run

I recently deployed a Next JS application to Google Cloud Run, the app runs just fine except for the fact that the images are taking up to 30 seconds to fetch.

Here is a log copied from cloud run (with the image url changed for simplicity), opening the cloudinary url directly opens the picture in less than a second.

GET200 2.17KB 29s Chrome 111 msChrome 111 https://mywebsite/_next/image?url=cloudinaryurl.webp

As you can see its merely 2kb, so it makes no sense for it to take almost 30 seconds to load.

Another important detail is that this only happens the first time I load the website, tried it on my phone too and it also takes a few minutes to load assets.

Website is working as intended on development environment and the images have the same urls.

Thanks in advance!