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
- Install react-mosaic and import in in app
- Build app using a tool that targets native modules for the browser such as Snowpack
- 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 :-/
Fixed in 602b0d5