calibreapp/react-live-chat-loader

[Bug] dist bundle no longer transpiled to es5

nzjames opened this issue · 4 comments

Describe the bug

Between version 2.7.4 and 2.8.0 the dist/ portion of the package went from being transpiled to es5 to including nullish coalescing optional chaining in the output.

Reading the release notes of 2.8.0 it does not read like this was an intentional change in the output. This manifests as a regression blocking builds when using a resolution like ^2.7.4 while not transpiling node_modules.

How To Reproduce

  1. npm install react-live-chat-loader@2.7.4
  2. Inspect node_modules/react-live-chat-loader/dist/providers/chatwoot.js and note the transpiled output starting with "use strict"
  3. npm install react-live-chat-loader@2.8.0
  4. Inspect node_modules/react-live-chat-loader/dist/providers/chatwoot.js and note the optional chaining check on line 17 fisrtScript.parentNode?...

Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project’s Code of Conduct

I built the main branch using node 14 and I found the dist/ and module/ outputs transpiled closer to the output of v2.7.4.

Looking at .babelrc I suspect having the targets set to node

"@babel/preset-env",
{
  "targets": {
    "node": true
  }
}

and having the .tool-versions specify

nodejs 16.15.0

results in the output bundles being transpiled to node 16 which supports optional chaining so this is left in.

I'm not an expert in this space but would changing the targets to something like:

"@babel/preset-env",
{
  "targets": {
    "browsers": "last 2 versions"
  }
}

provide a generated output that is safer to use in browser?

Hey @nzjames, thanks for raising this one.

We were able to replicate the bug following the steps provided. It seems like the cause of the issue was likely a bump in the @babel/core dependency, as nothing changed in .tool-versions or .babelrc between 2.7.4 and 2.8.0.

Your solution above looks good to me (thanks for that!), so we’ll shoot to get a patch release with the fix rolled out shortly. Cheers!

hey there @robmorieson!

first of all, thank you so much for the great work. we truly appreciate it 🙏

I hate to be that person but, 😭 are there any updates regarding this issue? 😭

we had to manually transpile react-live-chat-loader via our webpack config as a workaround, but that's a bit suboptimal.

@altaywtf thanks for the gentle bump — this one did fall off the radar so very much appreciated.

Happy to report that a fix for this issue has now been merged and a patch release will be going out including the fix in the next few days.