I'm trying to build a single js file application with polakdot.js by using rollup to bundle everything together, but some of the polakdot.js libraries can't be resolved by the rollup node resolve plugin.

@polkadot/x-randomvalues (imported by @polkadot/x-randomvalues?commonjs-external)
@polkadot/x-textdecoder (imported by @polkadot/x-textdecoder?commonjs-external)
@polkadot/x-textencoder (imported by @polkadot/x-textencoder?commonjs-external)
@polkadot/x-fetch (imported by @polkadot/x-fetch?commonjs-external)

Is there some extra configuration that polkadot.js requires to bundle?

1 Answer 1


Browser bundles for the various packages are available in the polkadot-js GH org and also as part of the npm packages. These are indeed all built with rollup.

First off, not a bundling guru, so take this with a grain of salt.

My guess at your issue: all the x-* packages use export maps extensively, so it needs quite a recent version of the rollup node resolver to work - older version and known to have issues. So my first suggestion would be to ensure that -resolve and -commonjs are on the latest plugin versions, alongside rollup.

As to how polkadot-js bundles - it is not that easy to untangle, since it uses some scripts that are shared between the various repos the relevant bit there would be for the plugins added -

    plugins: [
      pluginAlias({ entries }),
      pluginResolve({ browser: true }),

Apart from some overrides for some packages there are no specific/additional build steps applied for the various packages, the above shared config applies to all.

  • Sorry for lacking background here, I was trying to build for nodejs, if I exclude these dependencies, they will not be bundled into the result file.
    – Mage Front
    Commented Jul 14, 2022 at 12:10
  • The above answer doesn't mean to exclude anything - rather it seems to focus on the actual rollup versions. From my reading, specifically the x-* packages, which is confirmed by the source, needs to be includes, but it requires new node resolution in rollup.
    – Xiu Hung
    Commented Jul 15, 2022 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.