Hey Im trying to customize my plans and pricing page by following one of Wix Wiz videos on Youtube.
The tutorial was done on Editor X but Im trying to do it on Wix Studio.
Ive made a file inside src > backend called plans.jsw and coded the below
import wixData from 'wix-data';
export const getPlans = async ()=> {
const results = await wixData.query("PaidPlans/Plans").find()
return results.items;
}
when I run the code I get the below error,
/usr/local/bin/node ./src/backend/plans.jsw
(node:220) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
warning:50
Process exited with code 1
Uncaught SyntaxError /user-code/src/backend/plans.jsw:1
import wixData from 'wix-data';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at compileFunction (vm:352:18)
at wrapSafe (internal/modules/cjs/loader:1032:15)
at Module._compile (internal/modules/cjs/loader:1067:27)
at Module._extensions..js (internal/modules/cjs/loader:1157:10)
at Module.load (internal/modules/cjs/loader:981:32)
at Module._load (internal/modules/cjs/loader:822:12)
at executeUserEntryPoint (internal/modules/run_main:77:12)
at <anonymous> (internal/main/run_main_module:17:47)
Could someone help me what Im doing wrong.
Thank you
Why you do not show your whole CODE ?
FRONTEND
& BACKEND
Looks like a SYNTAX-ERROR on BACKEND ?
And did you realy took a look into the VIDEO ???
It was even mentioned --> That the API you are using will be DEPRICATED soon.
And --> YES <-- it is like it is --> you are already using a DEPRICATED OLD VERSION of an API.
And --> YES <-- of course we have a SYNTAX-ERROR here, not even only a SYNTAX-ERROR, your whole code looks not very good.
Without have taken a look now onto the new Wix-Plans-APIs, i am almost sure, that you are not able to differ between BACKEND & FRONTEND, because your code it showing this clearly.
Is this your whole code?
import wixData from 'wix-data'; export const getPlans = async ()=> { const results = await wixData.query("PaidPlans/Plans").find() return results.items; }
a) You are importing Wix-Data-API, but i can not see that you are importing Wix-Pricing-Plans-API.
b) There is also a big difference BETWEEN an imported BACKEND-API and a FRONTEND-API.
c) How to get a pricing plan by ID....
import wixPricingPlansBackend from 'wix-pricing-plans-backend'; export function myGetPlanFunction() { const id = '001c0674-d7c9-4c77-acb5-b492b427b201'; return wixPricingPlansBackend.getPlan(id) .then((plan) => { console.log(plan); }) .catch((error) => { console.error(error); }); }
d) Doing the same with a transfered ID (from frontend if needed).
import wixPricingPlansBackend from 'wix-pricing-plans-backend'; export function myGetPlanFunction(id) { return wixPricingPlansBackend.getPlan(id) .then((plan) => { console.log(plan); }) .catch((error) => { console.error(error); }); }
First check the NEW APIs...
https://www.wix.com/velo/reference/wix-pricing-plans-backend/getplan