question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'ReactComponent' is not exported by lib

See original GitHub issue

Current Behavior

I am trying to bundle a svg publishable React ibrary, but when I try run build it fails with below error

Error during bundle: Error: 'ReactComponent' is not exported by <path/to/svg>

Expected Behavior

Build should be sucessful

Steps to Reproduce

Update project’s worspace.json with

"webpackConfig": "@nrwl/react/plugins/webpack",

Add typing to base tsconfig.base.json

"files": ["./node_modules/@nrwl/react/typings/image.d.ts"],

run

nx affected:build --base=remotes/origin/main --with-deps

Failure Logs

'elementType' is not exported by 'node_modules\prop-types\index.js'
'forwardRef' is not exported by 'node_modules\react\index.js'
'createElement' is not exported by 'node_modules\react\index.js'
'createElement' is not exported by 'node_modules\react\index.js'
Error during bundle: Error: 'ReactComponent' is not exported by <path to svg>
Bundle failed: iep-logos

Environment

node: 16.3

Appreciate it if someone could provide a fix this. We have tring to publish internal React library based on SVGs and this is turning out to be major blocker.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
smithad15commented, Mar 24, 2022

Can confirm that this is still an issue in the default setup for Nx

4reactions
doublemarkedcommented, Oct 4, 2021

Moved past this today by patching the rollup config to include svgr,

// workspace.json
   "rollupConfig": [
      "@nrwl/react/plugins/bundle-rollup",
      "packages/ui/bundle-rollup.cjs"
   ],
// packages/ui/bundle-rollup.cjs
const url = require('@rollup/plugin-url');
const svgr = require('@svgr/rollup').default;

module.exports = options => ({
    ...options,
    plugins: [ ...options.plugins, url(), svgr()],
});

Read more comments on GitHub >

github_iconTop Results From Across the Web

'ReactComponent' is not exported from svg - Stack Overflow
Since you are using create-react-app the SVGR library is already installed and being used to process SVG files as a ReactComponent.
Read more >
Extending Rollup configuration for NX - Anton Ball
Error during bundle: Error: 'ReactComponent' is not exported by libs/library-name/src/lib/Icons/activity-log.svg Bundle failed: library-name.
Read more >
JavaScript default exports aren't always fun, or how I wasted 4 ...
Normally React components are default exports, and other things such as PropTypes and functions / hooks are exported as named exports. But in ......
Read more >
Rollup Config for React Component Library With TypeScript + ...
I am by no means a master in Rollup nor this is a definitive guide in building a React Component Library. I am...
Read more >
How to Create and Publish a React Component Library
Because we are creating a library, we are going to create index files for each tier, and export our components from each one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found