Appear to be getting 2 instances of globals - one in the remix serverside code (action, loader) & one in the server.js hosting code. Does that make sense? #9790
-
Our express/koa server initialises/configures our logging (lg4js). However, it appears that when we import the logger from our action code, we are getting an un-initialised instance. How is that possible? Is it expected? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Yes, unfortunately, it's expected. When you import the logger from your server file, you're importing it from the So you actually have two loggers: the one in (for example) I believe you wouldn't have that problem if you used https://github.com/kiliman/remix-express-vite-plugin because the server file wouldn't exist. I hope the Remix team is aware that this is confusing and can find a solution in the future. |
Beta Was this translation helpful? Give feedback.
-
Ahh, actually, that makes sense. Many thanks. We have elected to pass the log4js singleton in via the dependency injection (context). |
Beta Was this translation helpful? Give feedback.
Yes, unfortunately, it's expected.
When you import the logger from your server file, you're importing it from the
app
folder. When you import it from other files, what's actually running is the code in thebuild
folder.So you actually have two loggers: the one in (for example)
app/logger.js
and the one inbuild/server/index.js
. Both are being used when you run your app.I believe you wouldn't have that problem if you used https://github.com/kiliman/remix-express-vite-plugin because the server file wouldn't exist.
I hope the Remix team is aware that this is confusing and can find a solution in the future.