Use the .env File - Issue [RESOLVED]

[FIXED]: A fix has been pushed onto the fcc-bground-package, and this should no longer be a problem. If you started this project recently, you will likely need to:

  • Open the terminal/shell
  • Run the command npm update --save
  • Restart the app

As of <04/02/2021, a change has caused the above mentioned lesson to be uncompletable. Some have also been unable to complete:

  • Implement a Root-Level Request Logger Middleware
  • Chain Middleware to Create a Time Server

Error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at /home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:91:26

The error in full:

Error
SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at /home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:91:26
    at IncomingMessage.<anonymous> (/home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:33:7)
    at IncomingMessage.emit (events.js:315:20)
    at IncomingMessage.Readable.read (_stream_readable.js:505:10)
    at flow (_stream_readable.js:1005:34)
    at resume_ (_stream_readable.js:986:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at /home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:99:28
    at IncomingMessage.<anonymous> (/home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:33:7)
    at IncomingMessage.emit (events.js:315:20)
    at IncomingMessage.Readable.read (_stream_readable.js:505:10)
    at flow (_stream_readable.js:1005:34)
    at resume_ (_stream_readable.js:986:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
_http_outgoing.js:518
    throw new ERR_HTTP_HEADERS_SENT('set');
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:518:11)
    at ServerResponse.header (/home/runner/boilerplate-express-2/node_modules/express/lib/response.js:771:10)
    at ServerResponse.send (/home/runner/boilerplate-express-2/node_modules/express/lib/response.js:170:12)
    at ServerResponse.json (/home/runner/boilerplate-express-2/node_modules/express/lib/response.js:267:15)
    at /home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:108:15
    at IncomingMessage.<anonymous> (/home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:33:7)
    at IncomingMessage.emit (events.js:315:20)
    at IncomingMessage.Readable.read (_stream_readable.js:505:10)
    at flow (_stream_readable.js:1005:34)
    at resume_ (_stream_readable.js:986:3) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

If you encounter this, the best course of action is to skip the lesson, and continue with the curriculum.

As nothing obvious has changed on freeCodeCamp’s side, this is likely an issue on Repl.it’s side.

Current Debugged Steps
  1. Tested code which previously used to pass - no longer passes
  2. Downgraded express package - no effect
  3. One user was able to pass, and the noticeable difference was their origin was not freecodecamp.org, when they submitted.
  4. All manor of sending data via stringifying etc.

Issue on GitHub: Use the .env File Challenge Issue · Issue #40915 · freeCodeCamp/freeCodeCamp (github.com)

6 Likes

I’ve seen that error before, in other projects, when I try to .json a response that is actually a 404 (and sent back a custom HTML 404 page).

Let report this on our tracker too. Do we have full steps to reproduce? I understand its intermittent.

I have opened an issue on GitHub.

Steps to reproduce are:

  1. Go to challenge mentioned
  2. Add code required to pass
  3. Submit code
  4. App throws error, and crashes, and does not pass tests.

I was able to reproduce every time. A Camper I was pair-programming with could not reproduce it at all, and I noticed their difference was, when they submitted, their origin was from some .repl domain, whilst the expected origin should be freecodecamp.org

1 Like

I have had the same error. It works fine until I submit it on freecodecamp. It then throws above error.

1 Like

Ah okay, I thought I was going insane lol. Thanks for the info.

2 Likes

A post was split to a new topic: Install and Set up Mongoose Express Error

LOL and there I was trying the impossible to pass this challenge. Thanks for the info.

1 Like

Is the error caused by it somehow interpreting HTML as JSON? I wonder if we, the users, can’t write some code to get around it. If we can’t, then hopefully this gets fixed upstream soon.

Once it’s fixed, email us please (just in case we don’t have this page opened up and miss the notification). Mine is REDACTED . Thanks.

I have removed your email address. This forum is indexed by Google and listing your email will result in spam.

Here i am sending my link to the code I am making on repl.it.
Thanks in advance. will be really helpful .
https://repl.it/@MonikaRanjeet/boilerplate-express-1#myApp.js

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.