Cannot find module 'backend/queries' in 'public/pages/wzotf.js'

Question:
I need help in fixing this issue, I have no experience in coding and have no idea how this works.

I was trying to publish my updated website when I received and error stating that “publishing was paused due to site code error”, I reach out to wix support and they basically told me they can’t help me. So I am here to ask for any assistance.

This is the error I have gotten (I have not touch any code on my website, so I have no idea why this even happened):

Status: Error
[/pages/Copy of Gr 11 Life Sicences.wzotf.js]: Cannot find module ‘backend/queries’ in ‘public/pages/wzotf.js’
[/pages/RECIPE.wzotc.js]: Cannot find module ‘backend/queries’ in ‘public/pages/wzotc.js’
[/pages/Gr 12 Life Science.wzotd.js]: Cannot find module ‘backend/queries’ in ‘public/pages/wzotd.js’
[/pages/Gr 10 Life Sciences.wzoth.js]: Cannot find module ‘backend/queries’ in ‘public/pages/wzoth.js’
[/pages/Gr 12 Math.wzotg.js]: Cannot find module ‘backend/queries’ in ‘public/pages/wzotg.js’
[/pages/Gr 11 Life Sicences.wzote.js]: Cannot find module ‘backend/queries’ in ‘public/pages/wzote.js’

[public/custom-elements/wix-default-custom-element.js]:
Error count: 1
error: Parsing error: Unexpected token < (1:1)

Product:
Wix Editor

What are you trying to achieve:
Fixing the error as fast as possible

What have you already tried:
I have scanned though it and read a wix guide on it, as well as talked to chatgpt, but not sure if chatgpt is correct, and don’t want to ruin my website with implementing code. Thousands of students relay in my website so want to make sure it works as intended

Additional information:
Here is what chatgpt has told me (how accurate is it?):

Here’s what we’ll cover:

  1. Creating a Web Module to hold your backend functions (since the original backend/queries is missing or not working).
  2. Updating Each Page to import and call the web module functions.
  3. Code Setup for both the web module and the pages.

Let’s proceed step by step.

Step 1: Create a Web Module for Public Access

  1. Add a New Web Module:
  • In the Wix Editor, open the Code Files section on the sidebar.
  • Navigate to Public & Backend and hover over Backend.
  • Click the plus icon (+) and select Add web module.
  • Name the new file queries.web.js. This will create a new file specifically designed to allow calls from the frontend.
  1. Define Publicly Accessible Functions in queries.web.js:
  • Open queries.web.js and define the functions you need for each page. Since all users need access, use Permissions.Anyone for each function.Here’s a sample setup:

javascript

Copy code

import { Permissions, webMethod } from "wix-web-module";

// Example function to retrieve data
export const fetchDataForPage = webMethod(Permissions.Anyone, (param) => {
  // Replace this with the actual logic you need
  return `Data for ${param}`;
});

// Add additional functions as needed
  1. Save the Module:
  • Save queries.web.js. This file now acts as the centralized backend for all pages needing the backend/queries module.

Step 2: Update Each Affected Page to Use the Web Module

Since your error messages refer to several pages (Copy of Gr 11 Life Sciences, Gr 12 Life Science, Gr 10 Life Sciences, etc.), follow these instructions for each page:

  1. Open Each Page in the Wix Editor:
  • Go to each page mentioned in the error messages.
  1. Update the Import Statement:
  • Replace any import statements that referenced backend/queries with the new queries.web.js file.Here’s the new import statement:

javascript

Copy code

import { fetchDataForPage } from 'backend/queries.web';
  1. Call the Function:
  • Update any code that previously called functions from backend/queries to use fetchDataForPage. Since web module functions are asynchronous, you need to use await or .then().

javascript

Copy code

// Example of using the new function
async function loadData() {
  try {
    const data = await fetchDataForPage("exampleParam");
    console.log(data); // Output: Data for exampleParam
    // Insert any logic to use this data on the page
  } catch (error) {
    console.error("Error fetching data:", error);
  }
}

loadData();

Step 3: Additional Configurations

  • Permissions: Since the function in queries.web.js is publicly accessible (Permissions.Anyone), you shouldn’t encounter permission issues. However, if you later want to restrict access, change the permission level.
  • Debugging: Use the Developer Console in the Wix Editor preview mode to troubleshoot any additional issues that come up after making these changes.

Example Code for queries.web.js and Each Page

queries.web.js (in Backend)

javascript

Copy code

import { Permissions, webMethod } from "wix-web-module";

// Public function accessible by all users
export const fetchDataForPage = webMethod(Permissions.Anyone, (param) => {
  // Logic to fetch or process data
  return `Data for ${param}`;
});

// Add other functions as needed

Sample Page Code (Replace for Each Affected Page)

For each affected page (Gr 11 Life Sciences, Gr 12 Life Science, etc.), use this structure:

javascript

Copy code

import { fetchDataForPage } from 'backend/queries.web';

async function loadData() {
  try {
    const data = await fetchDataForPage("Page Specific Parameter");
    console.log(data); // Log or display data as needed
    // Additional logic to display data on the page
  } catch (error) {
    console.error("Error fetching data:", error);
  }
}

loadData();

Final Checklist

  1. Create and Save queries.web.js in Backend.
  2. Update Each Page to import and call the function from queries.web.js.
  3. Test each page in preview mode to ensure data loads without errors.

This setup should resolve the “Cannot find module” errors by consolidating backend functions into the web module queries.web.js and making it accessible from all pages. If you need additional functionality or have specific parameters for each page, feel free to share, and I can help adjust the code accordingly!

Hi, testpapersinfo !!

ChatGPT is very reliable, but if you truly haven’t modified any of the code on Wix, then this may not be an issue that can be resolved by adjusting the code. Instead, if you’ve added any apps to Wix, it might be better to check those first. :thinking:

Also, if you understand the basics of code, using ChatGPT is fine. However, following everything ChatGPT says when you have no understanding at all can be very risky. If the context of the problem isn’t fully shared with ChatGPT, it might confidently provide incorrect information, so please be cautious. :raised_hands:

Line 13 and 14 in your screenshot—— did you add a custom element to your site? It has an error.