JavaScript dependencies not working with Netlify Deployment - Stack Overflow

I have a project which I am deploying on Netlify. When it is run locally using two packages pako and nb

I have a project which I am deploying on Netlify. When it is run locally using two packages pako and nbitfy to parse some nbt data, it works perfectly, however on the deployed site, it causes the error:

Uncaught (in promise) TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

I believe this is something to do with the fact that the app.js code is running client-side and Netlify does not include node_modules, but I am not very familiar with how this deployment works. If anyone can point me in the right direction on how to get dependencies and imports to work I would greately appreciate it.

Netlify site - /

GitHub -

Full code (works locally, but not on Netlify):

/* eslint-disable camelcase */

import * as NBT from "nbtify";

import pako from "pako";

document.addEventListener("DOMContentLoaded", async () => {
  const data = await fetch(
    `/lify/functions/fetchProfilesByUUID?uuid=666bb608-c287-4b47-aa1c-e775690cba66`,
  );

  const { profiles } = await data.json();

  let selectedProfile;

  // The selected profile is not always at the 0th index, so search for it
  for (const profile of profiles)
    if (profile.selected) selectedProfile = profile.members;

  // Note - the key is always the condensed version of the UUID (no dashes)
  for (const [key, value] of Object.entries(selectedProfile)) {
    if (key === "666bb608c2874b47aa1ce775690cba66") selectedProfile = value;
  }

  // At this point we have usable data
  const { rift } = selectedProfile;

  const { inventory } = selectedProfile;
  const { bag_contents } = inventory;
  const { talisman_bag } = bag_contents;

  const test = talisman_bag.data;

  const binaryString = atob(test);

  // 2. Convert binary string to Uint8Array
  const uint8Array = new Uint8Array(binaryString.length);

  for (let i = 0; i < binaryString.length; i++) {
    uint8Array[i] = binaryString.charCodeAt(i);
  }

  // 3. Gzip decompress
  const decompressedData = pako.ungzip(uint8Array, { to: "Uint8Array" });

  // 4. Convert decompressed data to ArrayBuffer
  const nbtBuffer = decompressedData.buffer;

  // 5. NBT parse
  const nbtData = await NBT.read(nbtBuffer);

  console.log(nbtData);

  console.log(rift);
});

I don't know what to try, I can't really identify the error or how to solve it - any pointers would help me. I read the Netlify docs and it should be running npm install from the root package json - but it still has the error:

{
  "name": "skyblock-profile-viewer",
  "version": "1.0.0",
  "description": "A tool to view Hypixel Skyblock profile stats and get tips on progression",
  "main": "index.js",
  "scripts": {
    "dev": "npx mix watch",
    "netlify": "netlify dev"
  },
  "prettier": {
    "plugins": [
      "prettier-plugin-tailwindcss"
    ]
  },
  "author": "Dalton F",
  "license": "MIT",
  "dependencies": {
    "@tailwindcss/postcss": "^4.0.9",
    "dotenv": "^16.4.7",
    "nbtify": "^2.2.0",
    "pako": "^2.1.0",
    "postcss": "^8.5.3",
    "tailwindcss": "^4.0.9"
  },
  "devDependencies": {
    "@eslint/js": "^9.21.0",
    "eslint": "^9.21.0",
    "globals": "^16.0.0",
    "laravel-mix": "^6.0.49",
    "prettier": "^3.5.2",
    "prettier-plugin-tailwindcss": "^0.6.11"
  }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744969733a4603895.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信