meteor / meteor-feature-requests

A tracker for Meteor issues that are requests for new functionality, not bugs.
Other
89 stars 3 forks source link

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

Open perbergland opened 3 years ago

perbergland commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.