ably-js icon indicating copy to clipboard operation
ably-js copied to clipboard

Update "Using WebPack" section in README about importing ably directly from static file

Open VeskeR opened this issue 8 months ago • 0 comments

ably-js v2 uses exports field in its package.json, so bundlers that respect this field (like webpack v5) won't be able to resolve import * as Ably from 'ably/build/ably.js' which is currently suggested in README here. It fails with Error: Module not found: Error: Package path ./build/ably.js is not exported from package ...\node_modules\ably (see exports field in ...\node_modules\ably\package.json).

Instead the correct workaround is to use alias setting in webpack config like this:

// webpack.config.js
const path = require('path');

module.exports = {
  module: {
    rules: [
      {
        resolve: {
          alias: {
            ably: path.resolve(__dirname, 'node_modules/ably/build/ably.js'),
          },
        },
      },
    ],
  },
};

See internal slack thread for more context.

┆Issue is synchronized with this Jira Task by Unito

VeskeR avatar Jun 14 '24 10:06 VeskeR