Hey guys,
I tried creating a common file for helper functions and constants but i wasn’t able to import them.
Please help how can i achieve that as it is causing a lot of duplicates.
Hello @Kashish_Maggu,
Please can you add the code of your helper and maybe the way you want to use it in another file so we can better help you?
Thanks,
lets just say like i want a same peice of code in 4-5 different smart actions, all in different routes.
for ex. function add(x, y) {
return x+y
}
i tried making a helper.js and tried importing it but it failed
What is your error, and how are you importing it ?
Something like this should work:
helper.js file
export function add(x, y) {
return x + y;
}
from your smart action file:
import { add } from 'path/to/your/helper';
And then you can use your helper function. Tell me if it helps
Kind regards,
hey Iclisson,
tried it but not working. giving error.
tried it with require as well
Hi @Kashish_Maggu if you use classique Node project, you must use require.
helper.js file
module.exports = function add(x, y) {
return x + y;
}
const add = require('path/to/your/helper');
tried but giving the error again
Please can you share with us your error