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.

WebpackError: TypeError: Cannot read property 'replace' of undefined

See original GitHub issue

Hi everybody !

I don’t know exactly if it’s a bug or if it’s a weird behavior for me ^^

I am developing a Gatsby website, and I want to use markdown-to-jsx in. I have to pull some data, map some arrays… and use Markdown to print text on my website. The problem is Markdown doesn’t accept empty field : <Markdown></Markdown>

But, what I want to do that ?

Because I don’t want to check all times if there is a text in my variable or not : <Markdown>MyArray[0].Variable1.text</Markdown>

I just want to it to print nothing if there is nothing πŸ˜„

My logs :

2:28:33 PM:   2 | //# sourceMappingURL=index.module.js.map
2:28:33 PM:   3 | 
2:28:33 PM: 
2:28:33 PM:   WebpackError: TypeError: Cannot read property 'replace' of undefined
2:28:33 PM:   
2:28:33 PM:   - index.module.js:1 
2:28:33 PM:     node_modules/markdown-to-jsx/dist/index.module.js:1:14571
2:28:33 PM:   
2:28:33 PM:   - index.module.js:1 
2:28:33 PM:     node_modules/markdown-to-jsx/dist/index.module.js:1:15150
2:28:33 PM:   
2:28:33 PM: 
2:28:33 PM: not finished Generating image thumbnails - 133.828s
2:28:33 PM: ​
2:28:33 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
2:28:33 PM: β”‚   "build.command" failed    β”‚
2:28:33 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
2:28:33 PM: ​
2:28:33 PM:   Error message
2:28:33 PM:   Command failed with exit code 1: gatsby build
2:28:33 PM: ​
2:28:33 PM:   Error location
2:28:33 PM:   In Build command from Netlify app:
2:28:33 PM:   gatsby build

Is it a bug or it is normal ?

Thank you everybody !

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
julienslcommented, Oct 23, 2020

Hi !

I am coming back on this bug. I had a similar error today :

WebpackError: TypeError: t.replace is not a function

Only because I forget a space in my Markdown tag : <Markdown> {TitlePlateforme || ""}</Markdown> ( between the <Markdown> and the {Title... )

Maybe you should prevent this too ? πŸ˜ƒ

Have a good day !

0reactions
Prabhakar-Poudelcommented, May 11, 2021

I think you should create a separate component:

const YourMarkdown = ({children, ...props}) => {
  if (!children?.length) return <></>
  return <Markdown {...props}>{children}</Markdown>
}

And replace all Markdown component use with YourMarkdown

Read more comments on GitHub >

github_iconTop Results From Across the Web

js: TypeError: Cannot read property 'replace' of undefined using
I wanted to replace /\r?\n|\r/g with empty string but got a type error "Cannot read property 'replace' of undefined".
Read more >
Next 10.0.6 with webpack 5 & custom server throws `Cannot ...
Next 10.0.6 with webpack 5 & custom server throws Cannot read property 'replace' of undefined #21703.
Read more >
TypeError: Cannot read property 'replace' of Undefined in JS
The "Cannot read property 'replace' of undefined" error occurs when calling the replace() method on a variable that stores an undefined value.
Read more >
Uncaught TypeError: Cannot read property 'replace' of ...
Uncaught TypeError: Cannot read property 'replace' of undefined from line 248 of ytprefs.min.js. I can't seem to figure out what's causing it or...
Read more >
Webpack Error: Cannot read property .toWebpackConfig of ...
TypeError : Cannot read property 'toWebpackConfig' of undefined at Object. ... Gemfile gem 'webpacker', '~> 6.x' # replace '.x' with whichever version isΒ ......
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