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:
- Creating a Web Module to hold your backend functions (since the original
backend/queries
is missing or not working). - Updating Each Page to import and call the web module functions.
- 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
- 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.
- 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, usePermissions.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
- Save the Module:
- Save
queries.web.js
. This file now acts as the centralized backend for all pages needing thebackend/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:
- Open Each Page in the Wix Editor:
- Go to each page mentioned in the error messages.
- Update the Import Statement:
- Replace any
import
statements that referencedbackend/queries
with the newqueries.web.js
file.Here’s the new import statement:
javascript
Copy code
import { fetchDataForPage } from 'backend/queries.web';
- Call the Function:
- Update any code that previously called functions from
backend/queries
to usefetchDataForPage
. Since web module functions are asynchronous, you need to useawait
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
- Create and Save
queries.web.js
in Backend. - Update Each Page to import and call the function from
queries.web.js
. - 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!