i'm trying to upload a javascript nodejs project to Heroku. Localhost works perfectly but when i try to upload it gives me a:
unable to parse error at :
The Error Message : Unmatched '}' at line 16, column 1
Full Json file:
{
"name": "reactbot",
"version": "1.0.0",
"description": "React bot for webpage",
"main": "index.js",
"engines": {
"node": "12.16.2",
"npm": "6.14.4"
},
"scripts": {
"start": "node index.js"
},
"author": "Ruhul",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"nodemon": "^2.0.3"
}
}
The package.json file defines the dependencies that should be installed with your application.
Be sure to use the correct JSON format.
e.g.
{
"name": "node-example",
"version": "1.0.0",
"description": "This example is so cool.",
"main": "web.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"example",
"heroku"
],
"author": "jane-doe",
"license": "MIT",
"dependencies": {
"express": "^4.9.8"
},
"engines": {
"node": "10.x"
}
}
Related
I get yarn loops when starting my server.
>Console Listener setup OK
>Started map fivem-map-hipster
>Started resource fivem-map-hipster
>[yarn] yarn install v1.22.5
>[yarn] [1/4] Resolving packages...
and then it loops and tries to resolve the package again.
My package.json looks like this:
{
"name": "webpack-builder",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async": "^3.1.0",
"webpack": "^4.41.2",
"worker-farm": "^1.7.0"
}
}
what am I missing?
Building the .dmg works and running the .dmg installer works. When I open the installed app, the app's icon appears in the Mac tool bar for a second and then disappears. An error window then appears that says "App quit unexpectedly."
The app installs and functions perfectly on Windows machines with .exe that Electron-builder had built. I am confused as to how the .dmg is not functioning and working the same way. Is my package.json missing something or incorrect?
I have also attempted to build a .pkg, but the same error occurs.
How I build the file:
Run react-scripts build
Run electron-builder
My pacakge.json:
{
"name": "data-entry",
"packageName": "Data Entry App",
"version": "1.0.1",
"license": "MIT",
"description": "An app to quickly enter survey data.",
"private": true,
"author": "xxx",
"homepage": "./",
"main": "src/start.js",
"productName": "Data Entry App",
"nsis": {
"createDesktopShortcut": "always",
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true
},
"repository": {
"type": "git",
"url": "xxx"
},
"build": {
"files": [
"app/**/*",
"node_modules/**/*",
"package.json"
],
"appId": "com.myapp.DataEntry",
"publish": {
"provider": "github",
"repo": "xxx",
"owner": "xxx"
},
"npmRebuild": false,
"directories": {
"buildResources": "assets"
},
"mac": {
"target": "dmg"
},
"win": {
"target": "nsis"
}
},
"dependencies": {
"#material-ui/core": "^4.9.1",
"#material-ui/icons": "^4.5.1",
"#material-ui/lab": "^4.0.0-alpha.41",
"electron-is-dev": "^1.1.0",
"electron-json-storage": "^4.1.8",
"electron-log": "^4.0.6",
"electron-store": "^5.1.0",
"electron-updater": "^4.2.0",
"firebase": "^7.8.1",
"grpc": "^1.23.3",
"http2": "^3.3.7",
"node": "^10.9.0",
"node-pre-gyp": "^0.12.0",
"notistack": "^0.9.7",
"react": "^16.11.0",
"react-csv": "^1.1.2",
"react-dom": "^16.11.0",
"react-scripts": "3.2.0",
"react-with-firebase-auth": "^1.3.0"
},
"scripts": {
"start": "react-scripts start",
"electron": "electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"react-build": "react-scripts build",
"dist-all": "electron-builder"
},
"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"
]
},
"devDependencies": {
"electron": "^7.1.8",
"electron-builder": "^20.44.4"
}
}
Hello this is my json file format and this works well on my local machine when I run node index.js.
{
"name": "a-simple-nodejs-website",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "node index.js"
},
"author": "Theodore Kelechukwu Onyejiaku",
"license": "ISC"
}
But Heroku tells me:
Application error
An error occurred in the application and your page could not be served...
You need to mention engine in package.json as below
{
"name": "a-simple-nodejs-website",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": "10.x"
},
"scripts": {
"test": "node index.js"
},
"author": "Theodore Kelechukwu Onyejiaku",
"license": "ISC"
}
Check your Application Port in index.js. if you set to static port change as below:
const PORT = process.env.PORT || 5000
pass this port in your server listen method.
There was no start script in the json file so add => "start": "node index.js".
Fool code sample is below
{
"name": "a-simple-nodejs-website",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "node index.js",
"start": "node index.js"
},
"author": "Theodore Kelechukwu Onyejiaku",
"license": "ISC"
}
I'm confused about Yarn Workspaces. I've followed this tutorial: https://medium.com/trabe/monorepo-setup-with-lerna-and-yarn-workspaces-5d747d7c0e91 but in one of the sub projects I still get packages added to node_modules which are duplicated from the root node_modules. Full test repo is here: https://github.com/donker/Dnn.React.Test
Root package.json:
{
"name": "dnn-react-test",
"version": "1.0.0",
"description": "DNN React Component Library",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dnnsoftware/Dnn.React.Common.git"
},
"scripts": {
},
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"lerna": "2.11.0"
}
}
Subproject package.json:
{
"name": "dnn-tooltip",
"version": "0.2.5",
"description": "Display an icon and associated tooltip showing a message from an array parameter",
"main": "index.js",
"scripts": {
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dnnsoftware/Dnn.React.Common"
},
"dependencies": {
"lodash": "4.17.10",
"react-portal-tooltip": "2.4.0",
"dnn-global-styles": "^0.0.5"
}
}
Result: packages/Tooltip/node_modules/lodash created.
Expected: Tooltip uses node_modules/lodash from the root folder.
Getting lerna and yarn to properly work together requires adding the following two key value pairs to your lerna.json:
"npmClient": "yarn",
"useWorkspaces": true
Although this does not directly relate to your question, I would also suggest changing
"workspaces": [
"packages/*"
],
to
"workspaces": [
"packages/**"
],
to make lerna pick up packages in subfolders (like /packages/components/button).
I am working on a command line that will install every required node for a nodejs project.
Currently you can do:
sudo gen-web-app express
and this will genereate everything you need to start developing for expressjs.
I'm working now on
sudo gen-web-app reactjs
Everything is working except I have to go manually in the package.json and add the startup script to the file.
I know this is possible using SED In BASH, but I need a little help using sed.
This is the file:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"nodemon": "^1.11.0",
"path": "^0.12.7",
"react": "^15.6.1",
"webpack": "^3.1.0",
"webpack-dev-server": "^2.5.1"
}
}
I want to replace the following, but I would appreciate a little help :)
"test": "echo \"Error: no test specified\" && exit 1"
with
"start": "webpack-dev-server"
Download and install jq - A command line JSON syntax aware parser which lets you modify .json files. For your example in question.
tmp=$(mktemp)
jq '.scripts.start = "webpack-dev-server" | del(.scripts.test)' input.json > "$tmp" && mv "$tmp" input.json
will produce the final .json file as
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"dependencies": {
"nodemon": "^1.11.0",
"path": "^0.12.7",
"react": "^15.6.1",
"webpack": "^3.1.0",
"webpack-dev-server": "^2.5.1"
}
}
You can play with jq in a free-playground developed at jqplay.org.
$ sed -ie 's/\"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"/\"start\": \"webpack-dev-server\"/g' file
$ cat file
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"dependencies": {
"nodemon": "^1.11.0",
"path": "^0.12.7",
"react": "^15.6.1",
"webpack": "^3.1.0",
"webpack-dev-server": "^2.5.1"
}
}
Another option using jq would be to simply overwrite the value of .scripts:
jq '.scripts = { start: "webpack-dev-server" }' file.json