nomcopter / react-mosaic

A React tiling window manager

Home Page:https://nomcopter.github.io/react-mosaic/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optional dependency on @blueprintjs/core causes error when used via native browser module

erictooth opened this issue · comments

Bug report

  • Package version(s): 4.0.0
  • Browser and OS versions: Chrome 81/MacOS

Steps to reproduce

  1. Install react-mosaic and import in in app
  2. Build app using a tool that targets native modules for the browser such as Snowpack
  3. Try to load app in the browser

Actual behavior

When loading the app, Chrome shows the error:

Uncaught TypeError: Failed to resolve module specifier "@blueprintjs/core"

When building the app, Snowpack shows the warning (expected):

'@blueprintjs/core' is imported by 'node_modules/react-mosaic-component/lib/util/OptionalBlueprint.js', but could not be resolved.

Expected behavior

Using react-mosaic in an app distributed via native modules should not cause an error to be thrown due to an optional dependency.

For now I've added babel-plugin-transform-remove-imports to my project to remove import lines for blueprintjs. Any idea if there’s a better solution?

The same thing causes any app that depends on react-mosaic to fail building with parcel2:

$ parcel build src/index.js
🚨 Build failed.
@parcel/packager-js: `require.resolve` calls for excluded assets are only supported with outputFormat: 'commonjs'
/home/user/project/node_modules/react-mosaic-component/lib/util/OptionalBlueprint.js:32:9
  31 |         // https://github.com/nomcopter/react-mosaic/issues/109
> 32 |         require.resolve('@blueprintjs/core');
>    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  33 |         require.resolve('@blueprintjs/icons');
  34 |         (_a = require('@blueprintjs/core'), Classes = _a.Classes, OptionalBlueprint.Icon = _a.Icon);

The babel-plugin-transform-remove-imports workaround does not work with Parcel either, since it does not apply transforms to third-party packages :-/