r/learnreactjs • u/CatolicQuotes • Dec 12 '22
Using library causes app to not even start. How do I debug that?
I have imported this library: https://github.com/tyschroed/guillotine-packer
and used it in code:
import { packer } from "guillotine-packer";
function pack() {
const result = packer({
binWidth: 96,
binHeight: 48,
items: [
{
name: "test2",
width: 20,
height: 20,
},
{
name: "test",
width: 20,
height: 20,
},
],
});
}
which caused error in console:
Uncaught ReferenceError: process is not defined
at index.js:5:13
in code in this screenshot: https://i.imgur.com/vsDwN6G.png
and the page is blank, nothing renders.
I have tried to reproduce on code sandbox, in vanilla react there was no error so I had to use Vite React which causes error: link to sandbox
how do I debug this to know whats the issue? where to start?
3
Upvotes
4
u/TacoDelMorte Dec 12 '22 edited Dec 13 '22
“process” is typically only available to the backend, such as node.js, and not the frontend. It looks like that library is made for node.js to import and not the frontend. I assume you’re trying to run this as a frontend module.
That line is trying to read the environment variables from the system it’s being run on.
See:
https://nodejs.dev/en/learn/how-to-read-environment-variables-from-nodejs/
1
u/Chef619 Dec 12 '22
By vanilla react, I assume you mean create react app. When using Vite, they have a special way to access environment vars. https://vitejs.dev/guide/env-and-mode.html
Here’s a SO post about it. https://stackoverflow.com/questions/71083110/vue-uncaught-referenceerror-process-is-not-defined