The project concerned is onedrive-vercel-index.
I wished to use environment variables instead of editing confg/site.config.js
confg/site.config.js consists of variables and arrays. The variables were easy to deal with. process.env.VARIABLE || default-key worked fine for all the variables and is reflected by this commit
For the next part, the arrays, I referred to this stackoverflow question
The arrays concerned were googleFontLinks, protectedRoutes and links.
JSON.parse didn’t work, however .split() worked for “googleFontLinks” and “protectedRoutes”
for googleFontLinks I used process.env.WEBSITE_GOOGLE_FONT_LINKS?.split(', ') and for protectedRoutes I used process.env.WEBSITE_PROTECTED_ROUTES?.split(', ')
According to the stackoverflow question I referred to above, these work when I export the variables as follows:
export WEBSITE_PROTECTED_ROUTES="/Private, /safe/verysafe, /confidential"
export WEBSITE_GOOGLE_FONT_LINKS="https://fonts.googleapis.com/css2?family=Fira+Mono&family=Inter:wght@400;500;700&display=swap"
It only works with this particular syntax.
The only array that remains is “links”. process.env.LINKS?.split('}, ') doesn’t seem to work. Instead it throws the following error:
Type 'string' is not assignable to type '{ name: string; link: string; }'.
The export I used was export LINKS="{name:'GitHub',link:'https://github.com/spencerwooo/onedrive-vercel-index'}, {name:'GitLab',link:'https://gitlab.com/Box-boi'}"
This error appears regardless of whether $LINKS is set or not. In the case of googleFontLinks and protectedRoutes, if the respective environment variables are not set, then the default variables are used (reference).
Here, in the case of links, it doesn’t matter if the $LINKS environment variable is set or not. I always get the same error.
The full error is:
./src/components/Navbar.tsx:93:34
Type error: Argument of type '(l: { name: string; link: string;}) => JSX.Element' is not assignable to parameter of type '(value: string, index: number, array: string[]) => Element'.
Types of parameters 'l' and 'value' are incompatible.
Type 'string' is not assignable to type '{ name: string; link: string; }'.
91 |
92 | {siteConfig.links.length !== 0 &&
> 93 | siteConfig.links.map((l: { name: string; link: string }) => (
| ^
94 | <a
95 | key={l.name}
96 | href={l.link}
ELIFECYCLE Command failed with exit code 1.
I tried all the solutions mentioned in Defining an array as an environment variable in node.js
I tried process.env.LINKS?.split(', ') but to no avail.
I have tried exporting export LINKS="{name:'GitHub',link:'link1'}, {name:'GitLab',link:'link2'}" but the error still persists, despite the syntax being similar to that of protectedRoutes