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.

Build errors trying to import `react-markdown` but works in storybook

See original GitHub issue

Expected Behavior

I am able to install and build react-markdown as part of my app.

Current Behavior

Build fails with error with dependency trying to “require(‘path’)” but works in storybook.

Failure Information (for bugs)

I built a component that utilizes this as part of one of my libraries. I built it in storybook and everything worked well. The error did not surface until adding it to my app.

Steps to Reproduce

git clone https://github.com/countravioli/nx-react-build-error-react-markdown.git npm start

---- previous before I setup a repo ----

I bootstrapped a new nx project and chose react for my initial workspace. I added on dependency npm install react-markdown, imported it, and included it in app.tsx that is created in the workspace.

  1. npx create-nx-workspace@latest - choose react. I chose emotion for css.
  2. npm install react-markdown
  3. edit app.tsx, import ReactMarkdown from 'react-markdown' and add to the renderer <ReactMarkdown source='# hello' />`

If you can provide steps to reproduce from scratch, that would be enormously appreciated (i.e. where the first step is npx create-nx-workspace@latest repro-workspace)

Context

Please provide any relevant information about your setup:

Failure Logs

Entrypoint main = runtime.js runtime.js.map vendor.js vendor.js.map main.js main.js.map
Entrypoint polyfills = runtime.js runtime.js.map polyfills.js polyfills.js.map
chunk {main} main.js, main.js.map (main) 354 KiB ={runtime}= ={vendor}= [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 566 KiB ={runtime}= [initial]
chunk {runtime} runtime.js, runtime.js.map (runtime) 0 bytes ={main}= ={polyfills}= ={vendor}= [entry]
chunk {vendor} vendor.js, vendor.js.map (vendor) 1.3 MiB ={main}= ={runtime}= [initial] [rendered] split chunk (cache group: vendor) (name: vendor)

ERROR in /home/ryan/Code/test/foobar/node_modules/replace-ext/index.js
Module not found: Error: Can't resolve 'path' in '/home/ryan/Code/test/foobar/node_modules/replace-ext'

ERROR in /home/ryan/Code/test/foobar/node_modules/vfile/core.js
Module not found: Error: Can't resolve 'path' in '/home/ryan/Code/test/foobar/node_modules/vfile'

Other

Love nx so far, but still very green and not familiar with what’s going on behind the scenes. First ts project as well. Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
iskilbercommented, Jul 15, 2020

I have the same issue. I managed to find just a workaround only:

const ReactMarkdown = require('react-markdown/umd/react-markdown');
1reaction
countraviolicommented, Mar 27, 2020

@FrozenPandaz no problem To reproduce: git clone https://github.com/countravioli/nx-react-build-error-react-markdown.git npm start

To see it working in storybook npm run nx run core:storybook

Anecdotally, I bootstrapped another repo with create-react-app installed react-markdown and it also worked with a vanilla project there.

I tried a variety of things in my tsconfig to get it to work but no avail.

Read more comments on GitHub >

github_iconTop Results From Across the Web

rollup failed to resolve import "react-dom/client"
Which are like compile errors. ... ./sections/Home.jsx will work on your computer, but not on Heroku — change ... Having issues trying to...
Read more >
react-markdown - GitHub Pages
import React, { Component } from 'react'; class App extends Component { handleClick = () => { import('./moduleA') .then(({ moduleA }) => {...
Read more >
How to resolve "Cannot use import statement outside a ...
After trying all the possible solutions, this worked for me: The solution, that works for me: create a file named jest/mocks/@react-native- ...
Read more >
MDX and React
You can also import your own components defined in other files or ... which will make it automatically available in every MDX file, ......
Read more >
React Markdown component: the easy way to create rich text
You could also import the Markdown file directly, but using fetch means the data gets pulled at runtime, and we can work with...
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