Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature suggestion: optional process.env polyfill #236

Open
Caleb-T-Owens opened this issue Jan 25, 2024 · 0 comments
Open

Feature suggestion: optional process.env polyfill #236

Caleb-T-Owens opened this issue Jan 25, 2024 · 0 comments

Comments

@Caleb-T-Owens
Copy link
Contributor

What's the issue

With #235 and rails/propshaft#181 I'm now able to successfully import all the files for the tippy.js library.

After getting all of this working, I've found that tippy.js unfortunately in its ESM bundle refers to the node property process.env to determine whether it's in a production environment. There is a closed but unresolved issue (atomiks/tippyjs#990) for that library but it seems like there has recently not been much activity over there at all.

Why bother?

Whilst there is always the suggestion of "just use a different library" I think that if we're to make this transition over to no-build as seamless as possible for rails developers, it would make sense to have optional polyfills that resolve these node-related issues.

My suggestion

I would suggest having an optional (default false) kwarg on javascript_importmap_tags called polyfill_nodeisms, resulting in something like <%= javascript_importmap_tags polyfill_nodeisms: true %>

Shouldn't we get the library maintainers to ensure that nodeisms aren't included in their esm builds?

Yes - I think a great endgame would be to have all the nodeisms removed from packages, but that is a process that could take a bit of time, and cause some friction for developers transferring.

I think that it would be great to still encourage developers to prompt their library maintainers to remove the reliance of nodeisms, so I'd suggest that our ployfills should provide "warn" logs when they're used:

For example

window.process = {
  get env() {
    console.warn("Nodeism process.env has been used; You should not rely on nodeisms to being in the browser. If process.env is being used by a 3rd party dependency, consider submitting an issue to the maintainer")
    return "production"
  }
}

Screenshot 2024-01-25 at 21 48 39

Request for comments

I've identified process.env as being problematic, but don't have a good sample size of libraries. So I'd be interested in hearing if there are any other problematic nodeisms that people have found getting left in their esm libraries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant