meteor-feature-requests icon indicating copy to clipboard operation
meteor-feature-requests copied to clipboard

Protect developers against accidental import/require between client and server

Open perbergland opened this issue 4 years ago • 3 comments

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.

perbergland avatar Mar 01 '21 07:03 perbergland

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?

filipenevola avatar Mar 10 '21 20:03 filipenevola

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").

perbergland avatar Mar 16 '21 20:03 perbergland

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.

filipenevola avatar Mar 18 '21 15:03 filipenevola