Managing Packages with Npm - How to Use package.json

Managing Packages with Npm - How to Use package.json
0
#1

I have the following error:

Unexpected token < in JSON at position 0

this is the json code,
{
“//1”: “describes your app and its dependencies”,
“//2”: “https://docs.npmjs.com/files/package.json”,
“//3”: “updating this file will download and update your packages”,
“name”: “hello-express”,
“author”: “Sammy Khaleel”,
“version”: “0.0.1”,
“description”: “A simple Node app built on Express, instantly up and running.”,
“main”: “server.js”,
“scripts”: {
“start”: “node server.js”
},
“dependencies”: {
“express”: “4.16.3”
},
“engines”: {
“node”: “8.x”
},
“repository”: {
“url”: “https://glitch.com/edit/#!/hello-express
},
“license”: “MIT”,
“keywords”: [
“node”,
“glitch”,
“express”
],
}

#2

That error is not coming from this file.

#3

So, from where? there is not enough info in this module to help me troubleshoot the problem.

#4

This error is when JSON is expected, but HTML received.

#5

You trying parsing JSON.parse(youvar) a not stringified object.in somewhere in your code.

#6

I am not writing any code it is the first challenge in “managing packages with npm” module we were asked to write author name in package.json in a file hosted by glitch and then we should submit the link of glitch.

this is the link to the challenge:
https://learn.freecodecamp.org/apis-and-microservices/managing-packages-with-npm/how-to-use-package-json-the-core-of-any-node-js-project-or-npm-package

#7

Heya, your quotation marks are the wrong type, they shouldn’t be “” they should be "

Other than that, you also have a trailing comma near the end

package.json must be valid JSON

1 Like
#8

You should give a link to glitch project. click on share and tab code.
and there migth be < somewhere in this file you accidently type try ctrl+f and look for <

#9

I think the problem is with my link, may be I should sign up for an account on glitch. but in the challenge there is no mention on that.
I still unable to solve the issue

#10

I put the link to the actual app and the test is completed without the previous error but I still have an error that now I am unable to reproduce because glitch now prevent me from loading the app because I made too much requests (or that is my understanding).
Why this module is been abandoned when I tried to get a hint or ask for help I found this: This is a stub. Help our community expand it. any moderators here for the rescue?

#11

Did you check your quotation marks?

#12

I’ve provided the code above, you can see that it is a valid JSON.

#13

your quotation marks are the wrong type, they shouldn’t be “” they should be "

Did you check that they’re the right type? As in not slanted quotation marks but instead the ASCII quotation mark

Copying your above code definitely doesn’t work due to that

#14

This is the freecodecamp font that renders the double quote this way.

#15

Can you post it within triple backticks so we can see it unformatted?

#16

{
  "//1": "describes your app and its dependencies",
  "//2": "https://docs.npmjs.com/files/package.json",
  "//3": "updating this file will download and update your packages",
  "name": "hello-express",
  "author": "Sammy Khaleel",
  "version": "0.0.1",
  "description": "A simple Node app built on Express, instantly up and running.",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.16.4"
  },
  "engines": {
    "node": "8.x"
  },
  "repository": {
    "url": "https://glitch.com/edit/#!/hello-express"
  },
  "license": "MIT",
  "keywords": [
    "node",
    "glitch",
    "express"
  ]
}


#17

It’s really odd, but copypasting that works for me locally

I wonder if there’s a line-endings problem or something really daft like that, but that doesn’t seem likely if you’re editing in glitch directly

1 Like
#18

So I struggled with the same question for an hour or so until I went to the fcc project github link and saw how different the files are compared to the glitch project that popped up.

You need to start the project from this code. I did not want to do the whole clone and link it all to glitch so I just created the files and copied the contents into a glitch project. Lo and behold it works now.

Here’s my working glitch project: https://onyx-rake.glitch.me/

I hope it helps!

#19

Make sure you are submitting the actual application URL and not the edit URL. When editing your project on Glitch, click Show Live at the top left, and submit that URL to FCC.

2 Likes
#20

Thanks!

This is what worked for me. The “share” link that you see in the glitch editor doesn’t share your live project url it shares the link to edit your project on glitch