diff --git a/packages/react/plugins/bundle-rollup.ts b/packages/react/plugins/bundle-rollup.ts index 4db8954e0770d..b83364dd19bb6 100644 --- a/packages/react/plugins/bundle-rollup.ts +++ b/packages/react/plugins/bundle-rollup.ts @@ -1,8 +1,5 @@ import * as rollup from 'rollup'; -const url = require('@rollup/plugin-url'); -const svg = require('@svgr/rollup'); - function getRollupOptions(options: rollup.RollupOptions) { const extraGlobals = { react: 'React', @@ -26,17 +23,26 @@ function getRollupOptions(options: rollup.RollupOptions) { }; } - options.plugins = [ - svg({ - svgo: false, - titleProp: true, - ref: true, - }), - url({ - limit: 10000, // 10kB - }), - ...options.plugins, - ]; + // React buildable libs support SVGR, but not for React Native. + // If imports fail, ignore it. + try { + const url = require('@rollup/plugin-url'); + const svg = require('@svgr/rollup'); + + options.plugins = [ + svg({ + svgo: false, + titleProp: true, + ref: true, + }), + url({ + limit: 10000, // 10kB + }), + ...options.plugins, + ]; + } catch { + // Ignored for React Native + } return options; }