nomcopter / react-mosaic

A React tiling window manager
https://nomcopter.github.io/react-mosaic/
Other
4.38k stars 224 forks source link

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

Closed erictooth closed 3 years ago

erictooth commented 4 years ago

Bug report

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?

jbaiter commented 4 years ago

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 :-/

nomcopter commented 3 years ago

Fixed in 602b0d5447d8ffd23a0cbf3fca917c5736735ecd