monorepo: `inlang module build` should fail if node (or other non-browser) APIs are used

Problem

Critical bugs occur in production like https://github.com/inlang/monorepo/issues/1530 because inlang module build is not failing when node (or other non-browser) APIs are used.

Proposal

Validate during the build step that no non-browser APIs are used.

How

Add an esbuild plugin to the inlang module build command that throws if node imports are encountered.

https://github.com/inlang/monorepo/blob/d7710fcf2427aad5f53125f7f52375fa468e91e9/inlang/source-code/cli/src/commands/module/build/command.ts#L28-L41

Additional information

  • node APIs can still be be polyfilled. validation ensures that they are actually polyfilled (the reason why https://github.com/inlang/monorepo/issues/1530 was caused)
  • polyfilling by default (what we used to do) is setting up the ecosystem to be non-web compliant aka a no-go

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 26 (12 by maintainers)

Most upvoted comments

@A-N-uraag that is a good remark. I fear that a whitelist approach requires us to constantly update the whitelist as more APIs become available. The urge to import cloudflare worker apis is much lower than node’s apis. hence, i think the blacklist node api’s approach is sufficient for now.

thanks for raising the issue!

@samuelstroschein You really don’t need to assign, I would suggest let it open for everyone. Since this is a bit complex (bundling related, esbuild API) making it open for everyone would allow people to provide their own solutions, you could simply select anyone of the raised PR which does satisfy your needs.