Unexpected token in JSON at position 0 in react native (expo cli) - json

I have tried searching the web and deleting the node module twice and restarting the pc nothing seems to work.
This is the exact error.
Starting project at C:\Users\Admire\OneDrive\Documents\Projects\project-dharan\app
JsonFileError: Error parsing JSON:
└─ Cause: SyntaxError: Unexpected token in JSON at position 0
1 |
| ^
JsonFileError: Error parsing JSON:
└─ Cause: SyntaxError: Unexpected token in JSON at position 0
1 |
| ^
at parseJsonString (C:\Users\Admire\AppData\Roaming\npm\node_modules\expo\node_modules#expo\json-file\build\JsonFile.js:160:19)
at Function.readAsync (C:\Users\Admire\AppData\Roaming\npm\node_modules\expo\node_modules#expo\json-file\build\JsonFile.js:139:12)
at async getPackageVersionAsync (C:\Users\Admire\AppData\Roaming\npm\node_modules\expo\node_modules#expo\cli\build\src\start\doctor\dependencies\validateDependenciesVersions.js:140:25)
at async Promise.all (index 7)
at async resolvePackageVersionsAsync (C:\Users\Admire\AppData\Roaming\npm\node_modules\expo\node_modules#expo\cli\build\src\start\doctor\dependencies\validateDependenciesVersions.js:118:44)
at async getVersionedDependenciesAsync (C:\Users\Admire\AppData\Roaming\npm\node_modules\expo\node_modules#expo\cli\build\src\start\doctor\dependencies\validateDependenciesVersions.js:88:29)
at async validateDependenciesVersionsAsync (C:\Users\Admire\AppData\Roaming\npm\node_modules\expo\node_modules#expo\cli\build\src\start\doctor\dependencies\validateDependenciesVersions.js:49:27)
at async startAsync (C:\Users\Admire\AppData\Roaming\npm\node_modules\expo\node_modules#expo\cli\build\src\start\startAsync.js:109:9)
I have found the solution in the subredit for the identical problem but there is no way I can follow the solution mentioned in the link
this is my package json file
{
"name": "project-dharan",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"#react-navigation/native": "^6.1.2",
"#react-navigation/native-stack": "^6.9.8",
"expo": "^47.0.13",
"expo-status-bar": "~1.4.2",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-native": "0.70.5",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "~3.18.0",
"react-native-svg": "13.4.0",
"react-native-svg-transformer": "^1.0.0",
"react-native-web": "~0.18.7"
},
"devDependencies": {
"#babel/core": "^7.12.9"
},
"private": true
}

Related

How to run front end and back end in same port to deploy in tomcat server?

I am using reactjs in the front end and node js ,express js in backend which connects to the MySQL DB.
Both are two different folders where generally I was using on different ports.
how to combine them to deploy in tomcat server . what is the right method to do this ?
This is the index file from the backend folder inside my front end folder
....
....
app.post('/data/tournament/registration',(request, response)=>{
console.log(request.body);
connection.query("INSERT INTO registrationdata VALUES ?"
,[request.body],function(error, result, fields){
if(error){
throw error;
}else{
console.log(JSON.stringify(result));
response.send(JSON.stringify(result))
}
});
});
app.listen(8080,()=>{
console.log("Connected to port 8080");
});
....
....
The package JSON file from the backend folder inside the front end folder
{
"name": "mysql_db",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node src/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"mysql": "^2.18.1"
}
}
I use axios in the front end to fetch the data from backend.
import axios from 'axios';
export default axios.create({
baseURL:'http://localhost:8080'
});
I use the axios instance like in my front end to fetch from backend.
....
....
export const fetchTournaments=()=>async(dispatch)=>{
await mysqlDB.get('/data/tournament/fetch')
.then((response)=>{
console.log(response);
if(response.data !== {}){
dispatch( {
type: ActionTypes.FETCH_TOURNAMENT_SUCCESS,
payload:response.data
});
console.log("Fetched tournament")
History.push('/tournaments')
}else{
dispatch({type:ActionTypes.FETCH_TOURNAMENT_FAILED});
console.log("failed to Fetch tournament")
}
})
.catch((error)=>console.error(error));
};
....
....
This is the package json file of the front end which is basically the root folder
{
"name": "chess4loudoun",
"version": "0.1.0",
"private": true,
"dependencies": {
"#date-io/moment": "^1.3.13",
"#material-ui/core": "^4.9.14",
"#material-ui/icons": "^4.9.1",
"#material-ui/pickers": "^3.2.10",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"concurrently": "^5.2.0",
"material-table": "^1.57.2",
"moment": "^2.26.0",
"react": "^16.13.1",
"react-countdown": "^2.2.1",
"react-dom": "^16.13.1",
"react-google-login": "^5.1.20",
"react-material-ui-carousel": "^1.4.5",
"react-redux": "^7.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"redux": "^4.0.5",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start ",
"build": "react-scripts build ",
"test": "react-scripts test",
"eject": "react-scripts eject",
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
UPDATE
As for your other question about where to put your xml file etc that we discussed in comments, you will want to use this in your web.xml file to handle any 404 as per https://create-react-app.dev/docs/advanced-configuration/
<error-page>
<error-code>404</error-code>
<location>/index.html</location>
</error-page>
For Development you can use:
Add this in your express server.js or w/e
app.listen(8080)
Then in your React App's package.json use:
"proxy": "http://localhost:8080"
In production you will want to use the path module to serve the static react files...
const express = require('express')
const path = require('path')
const app = express()
app.use(express.static(path.join(__dirname, 'build')))

An unexpected error occurred: "/home/kudzie/portfolio/package.json: Unexpected token } in JSON at position 575"

trying to build a GitHub portfolio and host it on Namecheap so having this error: An unexpected error occurred: "/home/kudzie/portfolio/package.json: Unexpected token } in JSON at position 575".
{
"name": "portfolio",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "yarn run build",
"deploy": "gh-pages -d build"
},
"homepage":{
"http://kgomera.me/."
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
trying to build a GitHub portfolio and host it on Namecheap so having the error l posted above
On your "homepage" line:
"homepage":{
"http://kgomera.me/."
}
it is expecting a property, but all that's there is a string.
There are a couple ways of fixing this. The first, which is probably the way you're intending, is to change "homepage" from an object to a property:
"homepage":"http://kgomera.me/."
Secondly, you could add a key to make it into a property
"homepage":{
"url":"http://kgomera.me/."
}
Or lastly, you could make it into an array instead of an object by replacing the curly brackets with square brackets
"homepage":[
"http://kgomera.me/."
]
Just for future situations like this, here is a fantastic JSON validator and formatter that tells you exactly what is happening.

Unexpected token import, can not set up ES6 in my JS project with Mocha, Chai and Sinon

I am trying to set up a simple ES6 project to play with mocha, chai and sinon in the Terminal. But whenever I try to npm run test, I keep getting an error:
/Users/UserName/workspace/UnitTesting/mocha-sinon-chai/src/App.spec.js:1
(function (exports, require, module, __filename, __dirname) { import should from "chai";
^^^^^^
SyntaxError: Unexpected token import
Here are my:
1. Package.json:
{
"name": "mocha-sinon-chai",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "tests"
},
"dependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"sinon": "^4.4.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"mocha": "^5.0.1"
},
"scripts": {
"build": "babel src -d lib",
"test": "mocha ./tests/*.spec.js"
},
"author": "",
"license": "ISC"
}
2. .babelrc:
{
"presets": ["env"]
}
3. Root folder structure:
4. App.spec.js:
import should from "chai";
import { findOne } from "../src/App.js";
describe("App.js", function() {
it("should return true if predicate exists in the array", function() {
findOne([1, 2, 3], 3).should().be.true;
});
});
5. index.js is empty
6. App.js simply contains a normal JS function
I have checked many other similar issues here on Stackoverflow and GitHub and none of those solved my problem.
Adding this --require babel-core/register to test script inside package.json solved the problem:
"scripts": {
"build": "babel src -d lib",
"test": "mocha ./tests/*.spec.js --require babel-core/register"
},

How do I load webpack resource in JSON

I have the following code...
[
{
"number": 0,
"color": "blue",
"content": require('./first-card.pug')
}
...
]
When I try to run Webpack I see...
ERROR in ./src/app/jg/cards/cards.json
Module build failed: SyntaxError: Unexpected token r
at Object.parse (native)
Do I need to escape or something?

npm ERR! package.json must be actual JSON, not just JavaScript

Newbie node question. I am not able to get my project running anymore.
{
"name": "MyApp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js dev2"
},
"author": "",
"license": "ISC",
"dependencies": {
"async-await": "^0.1.32",
"asyncawait": "^1.0.3",
"body-parser": "^1.14.2",
"deasync": "",
"ejs": "^2.4.1",
"express": "^4.13.4",
"gulp": "^3.9.0",
"gulp-concat": "",
"gulp-filelist": "^0.2.0",
"gulp-foreach": "^0.1.0",
"gulp-remove-files": "0.0.3",
"gulp-rename": "",
"gulp-uglify": "",
"gulp-watch": "^4.3.5",
"mongoose": "^4.4.1",
"mongoose-ttl": "0.0.3",
"node-inspector": "^0.12.5",
"promise": "^7.1.1",
"rootpath": "^0.1.2"
},
"devDependencies": {
"browser-sync": "^2.11.1",
"gulp": "^3.9.1"
}
}
1726 error Failed to parse json
1726 error Unexpected token '\u0000' at 1:1
1726 error
1726 error ^
1727 error File: C:\Users\dir\AppData\Roaming\npm-cache\accepts\1.2.13\package\package.json
1728 error Failed to parse package.json data.
1728 error package.json must be actual JSON, not just JavaScript.
error Unexpected token '\u0000' at 1:1
seems that u have null character at first line and 1 character
can u provide package.json on pastebin or similar?