Code in folders creates problems

Using folders to store code creates unusual errors. I’ve documented one of several (possibly related) problems here.

During runtime without seemingly executing any code I see the message about a type error as is in the attached picture. The onReady event in the Home screen does not run.

Thank you for your time,
Robert Millward

https://robertmillward.wixsite.com/demo

Hi, can you please share this page’s code?

Per your request I am supplying code but at a new URL:
https://robertmillward.wixsite.com/demo2

The error message is very similar.
I’m not sure if the xyz folder and xyz.js is required to cause the problem.
Also, there is a file in the pqrFiles folder which contains just comments.
Except for the add(6,7) in $w.onReady(), this is all Wix code.

********** Home screen code, Wix default plus one call to add
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import add from ‘public/pqrFiles/pqr1.js’;

$w.onReady(function () {
//TODO: write your page related code here…
add(6,7);
});

********* Wix default code
// Filename: public/pqrFiles/pqr1.js
//
// Code written in public files is shared by your site’s
// Backend, page code, and site code environments.
//
// Use public files to hold utility functions that can
// be called from multiple locations in your site’s code.

export function add(param1, param2) {
return param1 + param2;
}

// The following code demonstrates how to call the add
// function from your site’s page code or site code.

/*
import {add} from ‘public/pqrFiles/pqr1.js’

$w.onReady(function () {
let sum = add(6,7);
console.log(sum);
});
*/

//The following code demonstrates how to call the add
//function in one of your site’s backend files.

/*
import {add} from ‘public/pqrFiles/pqr1.js’

export function usingFunctionFromPublic(a, b) {
return add(a,b);
}
*/

*********** Wix default code:
// Filename: public/xyzFiles/xyz1.js
//
// Code written in public files is shared by your site’s
// Backend, page code, and site code environments.
//
// Use public files to hold utility functions that can
// be called from multiple locations in your site’s code.

export function add(param1, param2) {
return param1 + param2;
}

// The following code demonstrates how to call the add
// function from your site’s page code or site code.

/*
import {add} from ‘public/xyzFiles/xyz1.js’

$w.onReady(function () {
let sum = add(6,7);
console.log(sum);
});
*/

//The following code demonstrates how to call the add
//function in one of your site’s backend files.

/*
import {add} from ‘public/xyzFiles/xyz1.js’

export function usingFunctionFromPublic(a, b) {
return add(a,b);
}
*/

// END of supplied code

It looks like you’re missing curly braces around the add import in the home screen code.

True, and that eliminated the error so thank you but many Wix examples show that curley braces are not required for a single import. [edit] I do see the difference regarding default export. I’ll see if this eliminates some other problems. Again, thank you, Tomer.

Yes, the difference is indeed the default export. Javascript modules can be confusing when you first use them (I know it was for me), but as everything it gets easier with time. Good luck :slight_smile: