Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'replace' of undefined #1120

Closed
kindkaktus opened this issue Jan 25, 2017 · 2 comments
Closed

TypeError: Cannot read property 'replace' of undefined #1120

kindkaktus opened this issue Jan 25, 2017 · 2 comments

Comments

@kindkaktus
Copy link

Description

Every now and then I get the following error. Js-beautify is used by the app implicitly by express-beautify 0.1.3 (as npm package)

 TypeError: Cannot read property 'replace' of undefined
 node_modules/js-beautify/js/lib/beautify-html.js:199
         html_source = html_source.replace(allLineBreaks, '\n');

Environment

OS: Linux Debian 8.6 x64 (jessie)
js-beautify v1.6.3
node.js v4.7.0
npm v4.0.5

@bitwiseman
Copy link
Member

What was your input?
Also, note current version of beautifier is 1.6.8.

@kindkaktus
Copy link
Author

kindkaktus commented Jan 26, 2017

Surprisingly is that the error is not reproducible on the same pages, but still happens now and then for different pages.

js-beautify v1.6.3 is used by express-beautify 0.1.3 so I can't directly influence the version of js-beautify I use.
Still the fix seems simple: just surround the statement in question with if (...) guards:

if (html_source ) {
    html_source = html_source.replace(allLineBreaks, '\n');
 }

I applied this fix by hand and my webserver stopped crashing. But ofc it would be better to have it in the upstream.

@bitwiseman bitwiseman added this to the v1.7.x milestone Jan 26, 2017
bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue May 21, 2018
bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue May 21, 2018
@bitwiseman bitwiseman modified the milestones: v1.7.x, v1.7.6 May 21, 2018
@bitwiseman bitwiseman modified the milestones: v1.8.0-rc2, 1.8.0 Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants