How to rename the attribute key in cheerio?

How do I rename foo attribute to baz with cheerio? (not the value, but the key).

I couldn’t find any docs about it, and the prop returns a string, so it doesn’t have an API I can use.

import "./styles.css";
import { CheerioAPI, load } from "cheerio";

console.clear();

const doc = load(`
<h1 foo="bar"></h1>
`);

console.log({ before: doc.html() });

doc("[foo]").each((i, el) => {
  console.log({ a: doc(el).attr("foo") });
});

console.log({ after: doc.html() });

codesandbox.io

How to extract values of a property inside an array of objects- JS

I have an array that loks like:

array =[
{id: "LAX"},
id: "BAS"},
id: "TES"},
id: "LAX"},
id: "LAX"},
id: "ATL"},
id: "BNA"},
id: "LAX"}
]

Here I’m trying to remove duplicate values of id using Set

[...new Set(array)]

is not currently helping.

I’m basically trying to achieve a result like:

`["LAX", "BAS", "TES"....]` // with no duplicates.

Any es6 recos for this?

thanks

Pug templating: how to use inline ternary conditional for text

How do I use a ternary conditional in a pug template for swapping text in a button?

This is what I have now…

p editing: #{editing}
// outputs true or false correctly for 'editing' value

button.btn(type='submit') #{editing ? 'Edit' : 'Add'} Product
// always outputs "Edit Product" text for button, regardless of 'editing' value

I’ve tried a number of possible solutions and searched high and low here and within pug documentation to no avail. Most ternary examples I find are for setting values for attributes, and I need to do it for text. I don’t want to do a multi-line IF/ELSE statement where I have to write two entire buttons to switch between, when it’s only a one-word difference. Any and all help appreciated.

How to iterate rows sequentially in sqlite3?

I want to iterate through my sqlite database synchronously.
Using async and sleep in db.each() does not delay the each callback since it does not use await on the callback internally:

var sleep = require("sleep");
var sqlite3 = require("sqlite3");
sqlite3.verbose();
var sqlite = require("sqlite");

(async () =>
{
    var db = await sqlite.open({
        filename: "./mydatabase.db",
        driver: sqlite3.Database
    });

    await db.each(`SELECT * FROM mytable`, async (err, row) =>
    {
        await sleep(10000);
        
        console.log(row);
    });
})();

I don’t want to use .all() since it will take a long time to load hundreds of thousands of records into memory.

I also don’t want to use LIMIT x OFFSET y since it will require re-running the query multiple times for each section I would check making it slower.

How can I iterate the sqlite results synchronously so that the next row isn’t fetched until I finish processing the current row?

Creating a tree-shaked bundle of Tabulator with Rollup

I would like to decrease the file size of Tabulator by creating bundles that only use the features I need for specific tables. I followed the advice in the docs for Core With Optional Modules, but I always end up with a bundle containing all the optional modules.

First I tried by downloading dist/js/tabulator_esm.js and creating a tabulator_rollup.js file with the contents:

import {Tabulator, FormatModule, EditModule} from './tabulator_esm';

Tabulator.registerModule([FormatModule, EditModule]);

var table = new Tabulator("#example-table", {
  //table setup options
});

Command line invocation used:

rollup tabulator_rollup.js --file tabulator_bundle.js --format iife

I also tried installing Tabulator from npm and referring to tabulator-tables in my tabulator_rollup.js file, running rollup -c against this configuration file:

import resolve from 'rollup-plugin-node-resolve';

export default {
  input: 'tabulator_rollup.js',
  output: {
    file: 'tabulator_bundle.js',
    format: 'iife',
  },
  plugins: [
    resolve({
      browser: true,
    }),
  ],
};

How to get all JSON names in this JSON array

I have this JSON file:

[
    {
      "name": "John",
      "age": "30"
    },
    {
      "name": "Maria"
      "age": "40"
    }
]

And I recieve this data (reading the json file) in a variable.

let jsonData = data (data is the content from Json file)

I’m trying to get all names (John & Maria).

But jsonData.nome is always undefined.

ActiveRecord::RecordNotFound (Couldn’t find Home without an ID):

hey am new to rails, i have homes table , users , and payments. I want something like this, when a user creates payments , it should contain user_id and home_id, i have managed to get user_id working but home_id failing.
`i have looked at many solutions here on stack overflow but i have not found the solution. I could be having problems with this line of code

home = Home.find(params[:home_id])

where i wanted to find home with an id the i use it while creating payments`

payment controller

class Api::V1::PaymentsController < ApplicationController
    before_action :set_payment, only: %i[ show edit update destroy ]
    before_action :authenticate_user!
    # GET /payments or /payments.json
    def index
     if user_signed_in?
        @payments = current_user.payments.order(created_at: :desc)
            render json: @payments
         else
            render json: {}, status: 401
        end
    end

    # GET /payments/1 or /payments/1.json
    def show
        if @payment
          render json: @payment
        else
          render json:@payment.errors  
      end
    end
   
    # GET /payments/new
    def new
      payment = current_user.payments.new
    #   home = Home.find(params[:home_id])  
    end
  
    # GET /payments/1/edit
    def edit
    end
  
    # POST /payments or /payments.json
    def create 
        home = Home.find(params[:home_id])
        if user_signed_in? 
            payment = home.payments.create(payment_params.merge(user_id: current_user.id))
            if payment = current_user.payments.create(payment_params, home)
             render json: payment, status: :created 
             else 
                render json: payment.errors, status: 400
            end
        else 
            render json: {}, status: 401
        end
    end
    
    # PATCH/PUT /payments/1 or /payments/1.json
    def update
      if @payment.update(payment_params)
        render json: {notice: "Payment was successfully updated." }
      else
        render json: { error: 'Unable to update payment' }
      end
    end
  
    # DELETE /payments/1 or /payments/1.json
    def destroy
      @payment.destroy
        render json: {notice: 'Payment succefully removed'}
    end
  
  private
    # Use callbacks to share common setup or constraints between actions.
    def set_payment
      @payment = Payment.find(params[:id])
    end

    # Only allow a list of trusted parameters through.
    def payment_params
      params.require(:payment).permit(:first_name, :last_name, :phone_number, :address, :money_paid, :date, :nin_number, :user_id, :home_id)
    end
end

schema

# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2022_12_15_071948) do

  create_table "homes", force: :cascade do |t|
    t.string "title"
    t.text "description"
    t.string "image_url"
    t.decimal "price", precision: 8, scale: 2
    t.string "availability", default: "Available", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  create_table "payments", force: :cascade do |t|
    t.string "first_name"
    t.string "last_name"
    t.string "phone_number"
    t.text "address"
    t.decimal "money_paid"
    t.string "nin_number"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.integer "home_id"
    t.date "date"
    t.integer "user_id"
    t.index ["home_id"], name: "index_payments_on_home_id"
    t.index ["user_id"], name: "index_payments_on_user_id"
  end

  create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  end

  add_foreign_key "payments", "homes"
  add_foreign_key "payments", "users"
end

home.rb

class Home < ApplicationRecord
    validates :title, :description, :image_url, :price,  :availability, presence: true
    validates :price, numericality: { greater_than_or_equal_to: 0.01 }
   

    validates :image_url, allow_blank: true, format: {
        with:
        %r{.(gif|jpg|png|jpeg)z}i,
        message: 'must be a URL for GIF, JPG, JPEG or PNG image.'
    }
    
    has_many :payments
end

payment.rb

class Payment < ApplicationRecord
    validates :first_name, :last_name, :phone_number, :address, :money_paid, :date, :nin_number, :user_id, presence: true
    belongs_to :user
    belongs_to :home
end

user.rb

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
         has_many :payments
end

anyone with any idea of how i can go about it. i want payments to include user_id and home_id which the user is paying for.

here are my routes if it could be a routing error

Rails.application.routes.draw do
  devise_for :users
  namespace :api do
    namespace :v1 do
      get 'homes/index'
      post 'homes/create'
      get '/show/:id', to: 'homes#show'
      delete '/destroy/:id', to: 'homes#destroy'
      # resources :payments

      get '/payments/index'
      post '/payments/create'
    end
   
  end

  root 'homes#index' 
  
  # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end

how to animated a swiper.js slider

This slider has 3 slides per view and also has a full-width background image. Whenever the slider changes, the background image will change according to the slider index. I tried animating it like the site https://stinna-it.nl/alle-projecten. Not only did I try to animate it, I tried to create exactly this slider using Swiper.js. For the animation, I used GSAP but I can only use autoAlpha for now; if I try to use other things like scale(0) to scale(1), it gets messed up.
I only use two image for example which changes according to index value. but the animation didn’t looks the reference website

  const imgs = document.querySelectorAll(".prjctbg");

  var swiper = new Swiper(".swiper-container", {
    pagination: {
      el: ".swiper-pagination",
      clickable: true,
    },
    spaceBetween: 1,
    slidesPerView: 2.5,
    centeredSlides: true,
    roundLengths: true,
    loop: true,
    loopAdditionalSlides: 30,
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
    on: {
      slideChangeTransitionStart: function () {
        // Get the current slide index
        var slideIndex = this.realIndex;
         // console.log(slideIndex);
        imgs.forEach((img) => {
          const index = img.getAttribute("data-index");
          if (index == slideIndex) {
            img.classList.add("activeBG");
          } else {
            img.classList.remove("activeBG");
          }
        });
        gsap.fromTo(
          ".activeBG",
          1,
          {
            autoAlpha: 0,
            scale: 1.2,
          },
          {
            autoAlpha: 1,
            scale: 1,
          }
        );
      },
    },
    breakpoints: {
      768: {
        slidesPerView: 1,
      },
    },
  });
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
    on: {
      slideChangeTransitionStart: function () {
        // Get the current slide index
        var slideIndex = this.realIndex;
         // console.log(slideIndex);
        imgs.forEach((img) => {
          const index = img.getAttribute("data-index");
          if (index == slideIndex) {
            img.classList.add("activeBG");
          } else {
            img.classList.remove("activeBG");
          }
        });
        gsap.fromTo(
          ".activeBG",
          1,
          {
            autoAlpha: 0,
            scale: 1.2,
          },
          {
            autoAlpha: 1,
            scale: 1,
          }
        );
      },
    },
    breakpoints: {
      768: {
        slidesPerView: 1,
      },
    },
  });

@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,400;0,500;0,600;1,200&display=swap');
* {
  margin: 0;
  padding: 0;
font-family: 'Poppins', sans-serif;
  box-sizing: border-box;
}

body a {
  text-decoration: none;
  color: #ffffff;
}


.projectSlider {
  width: 100vw;
  height: 100vh;
  position: relative;
}
.projectSlider .swiper-pagination-fraction,
.projectSlider .swiper-pagination-custom,
.projectSlider .swiper-container-horizontal > .swiper-pagination-bullets {
  bottom: 26px;
}
.projectSlider .swiper-slide.swiper-slide-prev {
  display: flex;
  justify-content: flex-end;
}
.projectSlider .swiper-slide.swiper-slide-next {
  display: flex;
  justify-content: flex-start;
}
.projectSlider .swiper-button-prev,
.projectSlider .swiper-container-rtl .swiper-button-next {
  background-image: url("../images/icons/prev.svg");
  left: inherit;
  right: 100px;
}
.projectSlider .swiper-button-next,
.projectSlider .swiper-container-rtl .swiper-button-prev {
  background-image: url("../images/icons/next.svg");
  right: 35px;
  left: auto;
}
.projectSlider .swiper-button-prev,
.projectSlider .swiper-button-next {
  top: 94%;
  width: 50px;
  height: 50px;
  background-size: contain;
  background-position: center;
}
.projectSlider .container {
  width: 100%;
  height: 100%;
}
.projectSlider .prjctbg {
  position: absolute;
  width: 100%;
  height: 100%;
  -o-object-fit: cover;
     object-fit: cover;
  filter: blur(8px);
  -webkit-filter: blur(8px);
}
.projectSlider .prjctbg.activeBG {
  z-index: 1;
  transition: transform 1000ms cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s, transform 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s;
}

.swiper-container {
  position: relative;
  width: 100%;
  height: 100%;
}

.swiper-slide {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 200ms cubic-bezier(0.165, 0.84, 0.44, 1);
  transform: scale(0.8);
  text-align: center;
}
.swiper-slide p {
  overflow: hidden;
  color: #fff;
  font-size: 1em;
}
.swiper-slide p span {
  transform: translateY(100px);
  transition: transform 1000ms cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s, transform 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s;
  display: block;
}
.swiper-slide h1 {
  color: #fff;
  font-size: 3.8em;
  line-height: 100%;
  transition: transform 1000ms cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s, transform 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s;
  margin: 0px 0px 30px 0px;
  transform: scale(0.5);
  font-weight: 600;
}
.swiper-slide.swiper-slide-active {
  transform: scale(1);
}
.swiper-slide.swiper-slide-active p {
  opacity: 1;
  transition-delay: 0.5s;
}
.swiper-slide.swiper-slide-active p span {
  transition: transform 1000ms cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s, transform 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s;
  transform: translateY(0px);
  display: block;
}
.swiper-slide.swiper-slide-active h1 {
  transition: transform 1000ms cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s, transform 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s;
  transition-delay: 0.15s;
  transform: scale(1);
}
   <link
  rel="stylesheet"
  href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.2/css/swiper.css"
/>
   <!-- slider section section -->
        <div class="projectSlider">
          <img
            src="https://i.im.ge/2022/12/16/dHOzYJ.windows-FV6Pma5U-98-unsplash.jpg"
            data-index="0"
            alt=""
            class="prjctbg"
          />
          <img
            src="https://i.im.ge/2022/12/16/dH2dSz.jenny-ueberberg-BaSeK7rwc1A-unsplash.jpg"
            data-index="1"
            alt=""
            class="prjctbg"
          />
          <img
            src="https://i.im.ge/2022/12/16/dHOzYJ.windows-FV6Pma5U-98-unsplash.jpg"
            data-index="2"
            alt=""
            class="prjctbg"
          />
          <img
            src="https://i.im.ge/2022/12/16/dH2dSz.jenny-ueberberg-BaSeK7rwc1A-unsplash.jpg"
            data-index="3"
            alt=""
            class="prjctbg"
          />
          <img
            src="https://i.im.ge/2022/12/16/dHOzYJ.windows-FV6Pma5U-98-unsplash.jpg"
            data-index="4"
            alt=""
            class="prjctbg"
          />
          <img
             src="https://i.im.ge/2022/12/16/dH2dSz.jenny-ueberberg-BaSeK7rwc1A-unsplash.jpg"
            data-index="5"
            alt=""
            class="prjctbg"
          />
          <div class="swiper-container">
            <div class="swiper-wrapper">
              <div class="swiper-slide">
                <div class="swiper-slide-container">
                  <a href="#" class="details">
                    <h1 class="elmt">
                      Audiovisual <br />
                      Design
                    </h1>
                    <p class="elmt">
                      <span> Video Installation</span>
                    </p>
                  </a>
                </div>
              </div>
              <div class="swiper-slide">
                <div class="swiper-slide-container">
                  <a href="#" class="details">
                    <h1 class="elmt">
                      Exhibition <br />
                      Design
                    </h1>
                    <p class="elmt">
                      <span> Multimedia Exhibition</span>
                    </p>
                  </a>
                </div>
              </div>
              <div class="swiper-slide">
                <div class="swiper-slide-container">
                  <a href="#" class="details">
                    <h1 class="elmt">
                      Texts and <br />
                      Images
                    </h1>
                    <p class="elmt">
                      <span> website + Print Magazine </span>
                    </p>
                  </a>
                </div>
              </div>
              <div class="swiper-slide">
                <div class="swiper-slide-container">
                  <a href="#" class="details">
                    <h1 class="elmt">
                      Material and <br />
                      Light
                    </h1>
                    <p class="elmt">
                      <span> Short Video</span>
                    </p>
                  </a>
                </div>
              </div>
              <div class="swiper-slide">
                <div class="swiper-slide-container">
                  <a href="./projectDetails.html" class="details">
                    <h1 class="elmt">
                      Dimension <br />
                      Design
                    </h1>
                    <p class="elmt">
                      <span> Rendered Image </span>
                    </p>
                  </a>
                </div>
              </div>
              <div class="swiper-slide">
                <div class="swiper-slide-container">
                  <a href="./projectDetails.html" class="details">
                    <h1 class="elmt">
                      App <br />
                      Design
                    </h1>
                    <p class="elmt">
                      <span> Sustainability App</span>
                    </p>
                  </a>
                </div>
              </div>
            </div>
            <!-- Add Pagination -->
            <div class="swiper-pagination"></div>
            <div class="swiper-button-prev"></div>
            <div class="swiper-button-next"></div>
          </div>
        </div>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.2/js/swiper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.3/gsap.min.js"></script>

value is returned as string while uploading an image when used with Controller

I have a component FileInput which abstracts the logic of dropping files, validating, removing and passing the dropped file to onchange callback. The way I am doing is not working. Value is returned as string (only name is passed).I could not figure out it.

Here is the code

export const FileUpload = (props: FileUploadProps) => {
  const {
    accept = ["image/*"],
    error = "",
    helperText,
    isRequired = false,
    label,
    labelClassName = "",
    helperTextClassName = "",
    maxFiles = 1,
    maxSize = 8000000,
    multiple = false,
    name,
    onChange,
    validationHandler = () => {},
    value = [],
    renderUpload,
    renderPreview,
  } = props;
  const [files, setFiles] = React.useState(value);

  const onDrop = React.useCallback(
    (acceptedFiles: File[], rejectedFiles: File[]) => {
      if (rejectedFiles && rejectedFiles.length > 0) {
        setFiles(files);
        onChange(name, files);
        rejectedFiles.forEach((file: File) => {
          file.errors?.forEach((err) => {
            if (err.code === "file-invalid-type") {
              validationHandler &&
                validationHandler(
                  name,
                  `Invalid file format. Only allow ${accept.join(", ")}`
                );
            } else if (err.code === "file-too-large") {
              const sizeMb = Math.ceil(maxSize / Math.pow(1024, 2));
              validationHandler &&
                validationHandler(name, `File is larger than ${sizeMb} Mb`);
            } else validationHandler && validationHandler(name, err.message);
          });
        });
      } else {
        const acceptedFile = files
          ? [
              ...files,
              ...acceptedFiles.map((file: File) =>
                Object.assign(file, {
                  preview: URL.createObjectURL(file),
                })
              ),
            ]
          : [
              ...acceptedFiles.map((file: File) =>
                Object.assign(file, {
                  preview: URL.createObjectURL(file),
                })
              ),
            ];
        if (acceptedFile.length > maxFiles) {
          validationHandler &&
            validationHandler(name, `Maximum ${maxFiles} files allowed.`);
        } else {
          setFiles(acceptedFile);
          validationHandler && validationHandler(name, "");
          acceptedFiles.forEach((file: File) => {
            const reader = new FileReader();
            reader.onabort = () => alert("File reading was aborted");
            reader.onerror = () => alert("file reading has failed");
            reader.readAsDataURL(file);
            reader.onloadend = () => {};
          });
          console.log("name", name, acceptedFile);
          onChange(name, acceptedFile);
        }
      }
    },
    [accept, maxSize, maxFiles, files, name, onChange, validationHandler]
  );

  React.useEffect(
    () => () => {
      files.forEach((file) => URL.revokeObjectURL(file.preview));
    },
    [files]
  );

  const handleRemove = React.useCallback(
    (file: File) => {
      const updatedFiles = files.filter((f) => f !== file);
      setFiles(updatedFiles);
      onChange(name, updatedFiles);
    },
    [files, name, onChange]
  );

  return (
    <div className="file-upload">
      {label && <Label id={name} className={labelClassName} label={label} />}
      {renderUpload(onDrop, files, handleRemove)}
      {renderPreview && (
        <div className="file-preview">{renderPreview(files, handleRemove)}</div>
      )}
      {helperText && typeof helperText === "string" ? (
        <p
          className={classNames(
            "italic text-gray-600 text-xs",
            helperTextClassName
          )}
        >
          {helperText}
        </p>
      ) : (
        helperText
      )}
    </div>
  );
};


export const FileInput = (props: FileInputProps) => {
  const {
    name,
    control,
    setValue,
    initialValues,
    errors,
    renderUpload,
    renderPreview,
    ...rest
  } = props;
  return (
    <>
      <Controller
        name={name}
        control={control}
        defaultValue={initialValues}
        render={({ field }) => {
          const { onChange, onBlur, value } = field;
          console.log("value", value);
          return (
            <FileUpload
              {...rest}
              name={name}
              errors={errors}
              onChange={(name, val) => {
                return onChange(name, val);
              }}
              value={value}
              renderUpload={(onDrop, files, handleRemove) => {
                if (renderUpload) {
                  return renderUpload(onDrop, files, handleRemove);
                }
              }}
              renderPreview={(files, onRemove) => {
                if (renderPreview) {
                  return renderPreview(files, onRemove);
                }
              }}
            />
          );
        }}
      />
    </>
  );
};

Why only name is set as value?

TypeError: Cannot read properties of undefined (reading ‘call’) on Next.js

I’m pretty new to Next.js and Typescript. I just wanna build a project using next.js and typescript and tailwind css using this simple create app command:
npx create-next-app -e with-tailwindcss my-project

Everything just went fine until I wanted to use Image tag using next/image and got an error

Unhandled Runtime Error
TypeError: Cannot read properties of undefined (reading 'call')

Call Stack
options.factory
file:///C:/Users/irwan/Projects/messenger-clone/meta-messenger/.next/static/chunks/webpack.js (710:31)
__webpack_require__
/_next/static/chunks/webpack.js (37:33)
fn
file:///C:/Users/irwan/Projects/messenger-clone/meta-messenger/.next/static/chunks/webpack.js (365:21)
require
node_modulesnextdistclientimage.js (7:15)
./node_modules/next/dist/client/image.js
file:///C:/Users/irwan/Projects/messenger-clone/meta-messenger/.next/static/chunks/app/layout.js (39:1)
options.factory
/_next/static/chunks/webpack.js (710:31)
__webpack_require__
file:///C:/Users/irwan/Projects/messenger-clone/meta-messenger/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (365:21)
__webpack_require__
node_modulesnextdistclientapp-index.js (26:16)
requireModule
node_modulesnextdistcompiledreact-server-dom-webpackclient.js (142:0)
initializeModuleChunk
node_modulesnextdistcompiledreact-server-dom-webpackclient.js (427:0)
resolveModuleChunk
node_modulesnextdistcompiledreact-server-dom-webpackclient.js (385:0)
eval
node_modulesnextdistcompiledreact-server-dom-webpackclient.js (668:0)

I’m sure the error is not about the url as I already add the domain to be whitelisted in my next.config.js file.

Here is my package json file:

{
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "next": "^13.0.7",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "@types/node": "18.11.3",
    "@types/react": "18.0.21",
    "@types/react-dom": "18.0.6",
    "autoprefixer": "^10.4.12",
    "postcss": "^8.4.18",
    "tailwindcss": "^3.2.1",
    "typescript": "^4.8.4"
  }
}

Last I’m using the beta feature(?) appDir on next.js 13. Here is my next.config.js file:

reactStrictMode: true,
  images: {
    domains: ['i.ibb.co']
  },
  experimental: {
    appDir: true
  }

Install webpack, didn’t work

Reload audio file from DB in JS

I press a button in browser:

function action() {
  var audio = new Audio("https://mydb.com/output.wav");
  audio.load();
  audio.play();
}

Then, I change my sound in DB with other button.

It changes in DB, but it does not reload in JS.

What can I do?

Thank you!

audio.load();

doesn’t help

Why react use angular brackets in rendering the component

I am new to the react as my background is ruby, so maybe it look a silly or noob question.
i come to the article
“Every component must begin with a capital letter. And once a component is declared, it can be written and used very similarly to an HTML element.” and also this
“To use this component in your application, use similar syntax as normal HTML: “

class Car extends React.Component {
  constructor() {
    super();
    this.state = {color: "red"};
  }

 render() {
    return <h2>I am a {this.state.color} Car!</h2>;
  }
}

root.render(<Car color="red"/>);

we have a car component created using class component so my question here is Why we use angular bracket here for creating instance of Car class. is this a syntax of creating instance of class in react.
Or
To use this component we have to use similar syntax as HTML. why?

I I am running the command npm run build — –ia32.it throws error

I have write this command and it shows me error

PS C:UsershpOneDriveDesktopelectron-script> npm run build — –ia32

[email protected] build
electron-builder “–ia32”

• electron-builder version=23.6.0 os=10.0.22000
• description is missed in the package.json appPackageFile=C:UsershpOneDriveDesktopelectron-scriptpackage.json
• writing effective config file=distbuilder-effective-config.yaml
• rebuilding native dependencies dependencies=@serialport/[email protected] platform=win32 arch=ia32
⨯ cannot execute cause=exit status 1
errorOut=npm ERR! code 1
npm ERR! path C:UsershpOneDriveDesktopelectron-scriptnode_modules@serialportbindings-cpp
npm ERR! command failed
npm ERR! command C:WINDOWSsystem32cmd.exe /d /s /c node-gyp-build
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration
npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON
npm ERR! gyp ERR! find Python checking if “python3” can be used
npm ERR! gyp ERR! find Python – “python3” is not in PATH or produced an error
npm ERR! gyp ERR! find Python checking if “python” can be used
npm ERR! gyp ERR! find Python – “python” is not in PATH or produced an error
npm ERR! gyp ERR! find Python checking if Python is C:UsershpAppDataLocalProgramsPythonPython39python.exe
npm ERR! gyp ERR! find Python – “C:UsershpAppDataLocalProgramsPythonPython39python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program FilesPython39python.exe
npm ERR! gyp ERR! find Python – “C:Program FilesPython39python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:UsershpAppDataLocalProgramsPythonPython39-32python.exe
npm ERR! gyp ERR! find Python – “C:UsershpAppDataLocalProgramsPythonPython39-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program FilesPython39-32python.exe
npm ERR! gyp ERR! find Python – “C:Program FilesPython39-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program Files (x86)Python39-32python.exe
npm ERR! gyp ERR! find Python – “C:Program Files (x86)Python39-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:UsershpAppDataLocalProgramsPythonPython38python.exe
npm ERR! gyp ERR! find Python – “C:UsershpAppDataLocalProgramsPythonPython38python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program FilesPython38python.exe
npm ERR! gyp ERR! find Python – “C:Program FilesPython38python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:UsershpAppDataLocalProgramsPythonPython38-32python.exe
npm ERR! gyp ERR! find Python – “C:UsershpAppDataLocalProgramsPythonPython38-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program FilesPython38-32python.exe
npm ERR! gyp ERR! find Python – “C:Program FilesPython38-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program Files (x86)Python38-32python.exe
npm ERR! gyp ERR! find Python – “C:Program Files (x86)Python38-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:UsershpAppDataLocalProgramsPythonPython37python.exe
npm ERR! gyp ERR! find Python – “C:UsershpAppDataLocalProgramsPythonPython37python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program FilesPython37python.exe
npm ERR! gyp ERR! find Python – “C:Program FilesPython37python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:UsershpAppDataLocalProgramsPythonPython37-32python.exe
npm ERR! gyp ERR! find Python – “C:UsershpAppDataLocalProgramsPythonPython37-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program FilesPython37-32python.exe
npm ERR! gyp ERR! find Python – “C:Program FilesPython37-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program Files (x86)Python37-32python.exe
npm ERR! gyp ERR! find Python – “C:Program Files (x86)Python37-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:UsershpAppDataLocalProgramsPythonPython36python.exe
npm ERR! gyp ERR! find Python – “C:UsershpAppDataLocalProgramsPythonPython36python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program FilesPython36python.exe
npm ERR! gyp ERR! find Python – “C:Program FilesPython36python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:UsershpAppDataLocalProgramsPythonPython36-32python.exe
npm ERR! gyp ERR! find Python – “C:UsershpAppDataLocalProgramsPythonPython36-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program FilesPython36-32python.exe
npm ERR! gyp ERR! find Python – “C:Program FilesPython36-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if Python is C:Program Files (x86)Python36-32python.exe
npm ERR! gyp ERR! find Python – “C:Program Files (x86)Python36-32python.exe” could not be run
npm ERR! gyp ERR! find Python checking if the py launcher can be used to find Python 3
npm ERR! gyp ERR! find Python – “py.exe” is not in PATH or produced an error
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! find Python **********************************************************
npm ERR! gyp ERR! find Python You need to install the latest version of Python.
npm ERR! gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
npm ERR! gyp ERR! find Python you can try one of the following options:
npm ERR! gyp ERR! find Python – Use the switch –python=”C:PathTopython.exe”
npm ERR! gyp ERR! find Python (accepted by both node-gyp and npm)
npm ERR! gyp ERR! find Python – Set the environment variable PYTHON
npm ERR! gyp ERR! find Python – Set the npm configuration variable python:
npm ERR! gyp ERR! find Python npm config set python “C:PathTopython.exe”
npm ERR! gyp ERR! find Python For more information consult the documentation at:
npm ERR! gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
npm ERR! gyp ERR! find Python **********************************************************
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Python installation to use
npm ERR! gyp ERR! stack at PythonFinder.fail (C:UsershpAppDataRoamingnvmv16.15.0node_modulesnpmnode_modulesnode-gyplibfind-python.js:330:47)
npm ERR! gyp ERR! stack at PythonFinder.runChecks (C:UsershpAppDataRoamingnvmv16.15.0node_modulesnpmnode_modulesnode-gyplibfind-python.js:159:21)
npm ERR! gyp ERR! stack at PythonFinder. (C:UsershpAppDataRoamingnvmv16.15.0node_modulesnpmnode_modulesnode-gyplibfind-python.js:228:18)
npm ERR! gyp ERR! stack at PythonFinder.execFileCallback (C:UsershpAppDataRoamingnvmv16.15.0node_modulesnpmnode_modulesnode-gyplibfind-python.js:294:16)
npm ERR! gyp ERR! stack at exithandler (node:child_process:406:5)
npm ERR! gyp ERR! stack at ChildProcess.errorhandler (node:child_process:418:5)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
npm ERR! gyp ERR! stack at onErrorNT (node:internal/child_process:478:16)
npm ERR! gyp ERR! stack at processTicksAndRejections (node:internal/process/task_queues:83:21)
npm ERR! gyp ERR! System Windows_NT 10.0.22000
npm ERR! gyp ERR! command “C:Program Filesnodejsnode.exe” “C:UsershpAppDataRoamingnvmv16.15.0node_modulesnpmnode_modulesnode-gypbinnode-gyp.js” “rebuild”
npm ERR! gyp ERR! cwd C:UsershpOneDriveDesktopelectron-scriptnode_modules@serialportbindings-cpp
npm ERR! gyp ERR! node -v v16.15.0
npm ERR! gyp ERR! node-gyp -v v9.0.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     C:UsershpAppDataLocalnpm-cache_logs2022-12-17T06_19_09_056Z-debug-0.log

Async and await does not work in sqllite3 in nodejs

I try to Insert query into sqlite database. But the function Does not work correctly.


const sqlite3 = require('sqlite3');
const { open } = require('sqlite');

async function main() {
    try {
        sqlite3.verbose();
        const ordersDb = await createDbConnection('./test.db');
        const orderProcessed = await orderAlreadyProcessed(ordersDb, "users");
        console.log('four ');
    } catch (error) {
        console.error(error);
    }
}


async function orderAlreadyProcessed(ordersDb, orderNumberStr) {
    try {
        console.log('two ');
        const query = `INSERT INTO users (first_name , last_name , username , password ) VALUES ('fdlfkld' , 'sfhdfjdk' , 'sdfhsdfhsd' , 'sdffs' )`
        const row = await ordersDb.run(query);
        console.log('three ');
    } catch (error) {
        console.error(error);
        throw error;
    }
}

function createDbConnection(filename) {
    return open({
        filename,
        driver: sqlite3.Database
    });
}

let one = [ 1 , 2, 3 ]

Promise.all(one.map(async()=>{
    await main();
}))

enter image description here

i need output like this

two
three
four
two
three
four
two
three
four

Sqlite does not work correctly , i need some help to rid the problem