Problem exporting function
Answered
Standard Chinchilla posted this in #help-forum
Standard ChinchillaOP
I have a hook with a function, that i need to call more than one archive, the function make a fetch and it return a promise. But when i do de npm run build...
Build optimization failed: found page without a React Component as default export in ....
My function is this:
@/pages/hooks/useWixClientServer
and i call it like this:
index.tsx
Build optimization failed: found page without a React Component as default export in ....
My function is this:
@/pages/hooks/useWixClientServer
export async function getWixClient() {
// my code
}and i call it like this:
index.tsx
import { getWixClient } from "@/pages/hooks/useWixClientServer";
export async function getStaticProps() {
const wixClient = await getWixClient();
// my code....
}Answered by Shy Albatross
idk, doesn't your
getWixClient() require something, like an env var?25 Replies
Shy Albatross
- what is "my code"?
- move hooks outside of pages dir
- React hooks should start with
- move hooks outside of pages dir
- React hooks should start with
use not get, is that really a hook or just a function? Probably not a hook since it's appended with "server"@Shy Albatross - what is "my code"?
- move hooks outside of pages dir
- React hooks should start with `use` not `get`, is that really a hook or just a function? Probably not a hook since it's appended with "server"
Standard ChinchillaOP
Yeees, it works when i move hooks thx
other question about getStaticPaths(). I deploy my app in local and I have no problem but when i put the same repository in vercel it throw a bug:
paths must be an array of strings or objects of shape { params: [key: string]: string }
but it´s okey the system (i think)
paths must be an array of strings or objects of shape { params: [key: string]: string }
but it´s okey the system (i think)
export async function getStaticPaths() {
const wixClient = await getWixClient();
let paths;
paths = await wixClient.products
.queryProducts()
.limit(10)
.find()
.then(({ items }) => {
return items.map((product) => ({
params: { id: product.slug },
}));
})
.catch((err) => {
console.error(err);
paths = [];
});
console.log(paths) // [ { params: { id: 'mouse-pad-red' } } ]
return { paths, fallback: false };
}in local works
Shy Albatross
long shot, but try
paths = [""]; as the default in the catch - I assume it's failing on wixClient because you're missing something in VercelStandard ChinchillaOP
the npm run build too
nop it doesn´t work
i give the complete error but i think is Irrelevant
Shy Albatross
that
undefined is your pathsStandard ChinchillaOP
i try to use an array of string (
paths must be an array of strings or...) but it doesn´t work neither@Shy Albatross that `undefined` is your paths
Standard ChinchillaOP
but....
Shy Albatross
I don't what is wixClient, but apparently it didn't throw, but your
paths are undefinedStandard ChinchillaOP
i try to define the variable directly with [ { params: { id: 'mouse-pad-red' } } ] but nothing
@Shy Albatross I don't what is wixClient, but apparently it didn't throw, but your `paths` are undefined
Standard ChinchillaOP
yes, but why in vercel is undefined and not in local
Shy Albatross
idk, doesn't your
getWixClient() require something, like an env var?Answer
Standard ChinchillaOP
yes... but is well placed
in local works i don´t now what is happeningin vercel
YOU ARE A GENIUS
IT WAS EN ENV VAR
XD
O.O discord does double command...?