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

Server timeout: Cannot read property 'replace' of undefined #16

Closed
deomaius opened this issue Jul 28, 2019 · 7 comments
Closed

Server timeout: Cannot read property 'replace' of undefined #16

deomaius opened this issue Jul 28, 2019 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@deomaius
Copy link

deomaius commented Jul 28, 2019

Pretty simple I run the server and all works fine and dandy before it times out.

CLI:

http to https redirection active.
Server running on port 443.
Unexpected error undefined:
TypeError: Cannot read property 'replace' of undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-box@0.1.0 build: `react-scripts build && CERT_PATH=./ssl/ serve build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-box@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-07-28T02_53_09_689Z-debug.log

Log:

1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@6.9.0
3 info using node@v10.16.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle react-box@0.1.0~prebuild: react-box@0.1.0
6 info lifecycle react-box@0.1.0~build: react-box@0.1.0
7 verbose lifecycle react-box@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle react-box@0.1.0~build: PATH: /usr/local/lib/node_modules/np$
9 verbose lifecycle react-box@0.1.0~build: CWD: /root/vldy.org/client
10 silly lifecycle react-box@0.1.0~build: Args: [ '-c', 'react-scripts build &&$
11 silly lifecycle react-box@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle react-box@0.1.0~build: Failed to exec build script
13 verbose stack Error: react-box@0.1.0 build: `react-scripts build && CERT_PAT$
13 verbose stack Exit status 1 
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/n$
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/n$
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
14 verbose pkgid react-box@0.1.0
15 verbose cwd /root/vldy.org/client
16 verbose Linux 4.15.0-52-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v10.16.0
19 verbose npm  v6.9.0
20 error code ELIFECYCLE
21 error errno 1
22 error react-box@0.1.0 build: `react-scripts build && CERT_PATH=./ssl/ serve $
22 error Exit status 1
23 error Failed at the react-box@0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional lo$
24 verbose exit [ 1, true ]
@daquinoaldo
Copy link
Owner

Hi, thank you for reaching out to me!

I've tried to reproduce, unsuccessfully. So, for the moment I can only share some considerations with you.

1. Stange output

CLI:

http to https redirection active.
Server running on port 443.

This is the normal log of https-localhost. A line is missing, though. These two lines are usually preceded by this one:

Serving static path: /your/static/path

where /your/static/path is build in your case.

Can you please check if it prints this line?

2. replace location in code

Unexpected error undefined:
TypeError: Cannot read property 'replace' of undefined

Supposing is not a React error, but an error concerning https-localhost, it should be related to an object on which I call the replace function that should be valid and instead is undefined.

There are two replace invocations: index.js row 44 and certs.js row 49.

This latter is executed when the mkcert function is invoked. so in generate (row 88), called in getCerts (row 107) only if CERT_PATH is not specified, so not our case. Furthermore, getCerts is called by app.listen in index.js row 22, but in the next line the app prints Server running on port 443. that is part of your log, hence the getCerts invocation seems to work correctly.

For that reason, I suppose the problem is in index.js row 44 and that the undefined object is req.headers["host"]. Anyway, this part of code is reached only when you send a request to http://localhost.

It is possible that you visited this page and that this error appears only after that action?

3. Truncated logs
Your logs seem to be truncated: pay attention to the $ at the end of some lines. The entire log may help in identifying the error.
You can obtain it with cat /root/.npm/_logs/2019-07-28T02_53_09_689Z-debug.log. Please don't use nano or other code editors since they used to truncate lines.

Thank you for your cooperation!

@daquinoaldo daquinoaldo added the missing info Information missing to determine whether is a bug or not label Jul 30, 2019
@deomaius
Copy link
Author

deomaius commented Aug 1, 2019

1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@6.9.0
3 info using node@v10.16.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle react-box@0.1.0~prebuild: react-box@0.1.0
6 info lifecycle react-box@0.1.0~build: react-box@0.1.0
7 verbose lifecycle react-box@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle react-box@0.1.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/root/vldy.org/client/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle react-box@0.1.0~build: CWD: /root/vldy.org/client
10 silly lifecycle react-box@0.1.0~build: Args: [ '-c',
10 silly lifecycle   'react-scripts build && CERT_PATH=/root/vldy.org/client/ssl serve build' ]
11 silly lifecycle react-box@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle react-box@0.1.0~build: Failed to exec build script
13 verbose stack Error: react-box@0.1.0 build: `react-scripts build && CERT_PATH=/root/vldy.org/client/ssl serve build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid react-box@0.1.0
15 verbose cwd /root/vldy.org/client
16 verbose Linux 4.15.0-52-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v10.16.0
19 verbose npm  v6.9.0
20 error code ELIFECYCLE
21 error errno 1
22 error react-box@0.1.0 build: `react-scripts build && CERT_PATH=/root/vldy.org/client/ssl serve build`
22 error Exit status 1
23 error Failed at the react-box@0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true 

It is possible that you visited this page and that this error appears only after that action?

Could well be the problem, i'm gonna set the alias for the ENV variable to be permanent and watch for changes instead of feeding in the absolute path.

@deomaius
Copy link
Author

deomaius commented Aug 1, 2019

I was calling react-scripts and serve simultaneously so, perhaps that had a conflicting issue, got the following output by adding the ssl path as a permanent environment variable and calling serve on it's own.

root@vldy:~/vldy.org/client# serve build
Serving static path: build
http to https redirection active.
Server running on port 443.

Will keep you posted on the state of operatives 🙌

@deomaius
Copy link
Author

deomaius commented Aug 2, 2019

Ok so it still occurred 😢

root@vldy:~/vldy.org/client# serve build
Serving static path: build
http to https redirection active.
Server running on port 443.
^XUnexpected error undefined:

TypeError: Cannot read property 'replace' of undefined

Strange though I access the HTTP gateway for the serve multiple times and it doesn't seems to effect the functionality, even though eventually the error just emits.

Attempting to change req.headers["host"] to req.headers("host") for any notable effects, seems that express has changed this structure afew times. ** fail **

Trying req.connection.remoteAddress instead

daquinoaldo added a commit that referenced this issue Aug 2, 2019
@daquinoaldo
Copy link
Owner

Thank you for the complete log. Unfortunately, it is not as useful as I hope.

Anyway, it really seems related to index.js row 44: req.headers["host"] is undefined.

I've tried to reproduce again, even with a permanent environment variable, but even after many tries it still works to me. Let me know if your tries fix the bug.

Meanwhile, I've prepared a workaround in case a fix is not found. It simply looks if req.headers["host"] is undefined and in that case just replace it with "localhost". Of course, it's not the best fix but should work if this tool is used on localhost as intended.

@daquinoaldo daquinoaldo added bug Something isn't working and removed missing info Information missing to determine whether is a bug or not labels Aug 2, 2019
@deomaius
Copy link
Author

deomaius commented Aug 3, 2019

Fixed by the hardcoding it as you said, thanks!

@deomaius deomaius closed this as completed Aug 3, 2019
@daquinoaldo daquinoaldo mentioned this issue Aug 3, 2019
4 tasks
daquinoaldo added a commit that referenced this issue Aug 3, 2019
@daquinoaldo
Copy link
Owner

Published v4.1.3 on npm with the fix. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants