Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Protect developers against accidental import/require between client and server #425

Open
perbergland opened this issue Mar 1, 2021 · 3 comments
Labels
in-discussion We are still discussing how to solve or implement it

Comments

@perbergland
Copy link

perbergland commented Mar 1, 2021

I just killed our app by including a module from /server into a /client module and then of course that module can’t be loaded in the browser (javascript error in runtime).

It would be a nice safety net if this was detected by the import/require scanner in meteor build tools and reported as an error.

@filipenevola filipenevola added the in-discussion We are still discussing how to solve or implement it label Mar 10, 2021
@filipenevola
Copy link
Collaborator

Are you using mainModule config on package.json in your apps or just using client / server directory names to coordinate the importing?

I'm asking as this would affect the warning implementation.

Also, in your case, it caused you to spend a lot of time or did you realize the mistake when you saw the error?

@perbergland
Copy link
Author

Ah yes, good question. We currently just rely on client/server/imports directory name conventions since it has worked well so far ("if it ain’t broke don’t fix it").

@filipenevola
Copy link
Collaborator

I believe we need to define better what would be the warning implementation here so we could classify this request as ready.

I don't know exactly what would be the best way to implement it, just checking the folder name could be a weak check.

Usually when I have important files that somehow are shared but they shouldn't be imported on client I throw an error inside a if (Meteor.isClient) in the top of the file.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in-discussion We are still discussing how to solve or implement it
Projects
None yet
Development

No branches or pull requests

2 participants