Skip to content

The cjs bundle is not fully es5 compatible #901

@bartsidee

Description

@bartsidee

The cjs bundle generated by tsdx is not fully es5 compatible

npx es-check es5 ./dist/redux-toolkit.cjs.development.js

results in the below error related to the const references found

ES-Check Error:
          ----
          · erroring file: dist/redux-toolkit.cjs.development.js
          · error: SyntaxError: The keyword 'const' is reserved (1412:0)
          · see the printed err.stack below for context
          ----

          SyntaxError: The keyword 'const' is reserved (1412:0)

this is caused by the below reference in redux-toolkit.cjs.development.js

const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";

const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";

which looks like a reference from symbol-observable package used by redux. It is however not referenced by the redux-toolkit generated cjs bundle. This is likely also the reason why this is not an issue for the ./dist/redux-toolkit.cjs.production.js as the minifier would removing the dead code.

A temporary workaround for us is to manually create an alias to ./dist/redux-toolkit.cjs.production.js however it would be great to get this fixed in the redux-toolkit pipeline itself.

Solution
I was able to solved this in the build pipeline by:

  • upgrading tsdx to the latest version (0.14.1)
  • and update the nested dependency of @rollup/plugin-commonjs to 12.0.0.

I just send a PR to tsdx project to ask if they would consider a version bump of the commonjs plugin jaredpalmer/tsdx#975

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions