Skip to content

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

Closed

Description

@deoidh

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! [email protected] build: `react-scripts build && CERT_PATH=./ssl/ serve build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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 [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 info lifecycle [email protected]~build: [email protected]
7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~build: PATH: /usr/local/lib/node_modules/np$
9 verbose lifecycle [email protected]~build: CWD: /root/vldy.org/client
10 silly lifecycle [email protected]~build: Args: [ '-c', 'react-scripts build &&$
11 silly lifecycle [email protected]~build: Returned: code: 1  signal: null
12 info lifecycle [email protected]~build: Failed to exec build script
13 verbose stack Error: [email protected] 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 [email protected]
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 [email protected] build: `react-scripts build && CERT_PATH=./ssl/ serve $
22 error Exit status 1
23 error Failed at the [email protected] build script.
23 error This is probably not a problem with npm. There is likely additional lo$
24 verbose exit [ 1, true ]

Activity

  1. daquinoaldo commented on Jul 30, 2019

    @daquinoaldo
    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!

  2. added
    missing infoInformation missing to determine whether is a bug or not
    on Jul 30, 2019
  3. deoidh commented on Aug 1, 2019

    @deoidh
    Author
    1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
    2 info using [email protected]
    3 info using [email protected]
    4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
    5 info lifecycle [email protected]~prebuild: [email protected]
    6 info lifecycle [email protected]~build: [email protected]
    7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
    8 verbose lifecycle [email protected]~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 [email protected]~build: CWD: /root/vldy.org/client
    10 silly lifecycle [email protected]~build: Args: [ '-c',
    10 silly lifecycle   'react-scripts build && CERT_PATH=/root/vldy.org/client/ssl serve build' ]
    11 silly lifecycle [email protected]~build: Returned: code: 1  signal: null
    12 info lifecycle [email protected]~build: Failed to exec build script
    13 verbose stack Error: [email protected] 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 [email protected]
    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 [email protected] build: `react-scripts build && CERT_PATH=/root/vldy.org/client/ssl serve build`
    22 error Exit status 1
    23 error Failed at the [email protected] 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.

  4. deoidh commented on Aug 1, 2019

    @deoidh
    Author

    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 🙌

  5. deoidh commented on Aug 2, 2019

    @deoidh
    Author

    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

  6. daquinoaldo commented on Aug 2, 2019

    @daquinoaldo
    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.

  7. added
    bugSomething isn't working
    and removed
    missing infoInformation missing to determine whether is a bug or not
    on Aug 2, 2019
  8. deoidh commented on Aug 3, 2019

    @deoidh
    Author

    Fixed by the hardcoding it as you said, thanks!

  9. added 2 commits that reference this issue on Aug 3, 2019
  10. daquinoaldo commented on Aug 3, 2019

    @daquinoaldo
    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

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions