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)

5 Likes
Unable to pass the test in use of .env file
Basic Node and Express .env file
What is wrong with my solution to this problem?
Basic Node and Express - Use the .env File get error Cannot set headers after they are sent to the client
Error when try to complete the challenge button
Problem with passing the .env exercise on Basic Node and Express Module
Stuck in .env file challenge
Project Failing on submission
I can't pass the serve static assets problem
The submission is correct but the the system is telling it wrong
APIs and Microservices .env Challenge
Why is this not working? API and Microservices .env
Please help guys! express library .env problem
Basic Node use .env file test fails with status 500
Use the .env File: Do not know why test fails
Stuck on Implement a Root-Level Request Logger Middleware
Basic Node And Express Use the .env File Not Passing Test And Breaking Server
"Use the .env File" test not working
Stuck on Use the .env file, Err: cannot send headers after they are sent to the client
Stuck on Implement a Root-Level Request Logger Middleware
Root level logger middleware should be active keeps showing
Managing Packages with Npm - How to Use package.json, the Core of Any Node.js Project or npm Package plesese help me
Basic Node and Express Use the .env file not working
Challenge Use the .env File!
Right answer isn't passing my test
Root level logger middleware should be active in year 2021 Feb
Use the .env File gives problem during solving
Use the .env File exercise: it changes as aspected but the test doesn't pass. Why?
What is wrong? help
Node challenges Json response
Response changed with dotenv not solved

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.

1 Like

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.

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