I can put a few more things in the package.json? - javascript

this is my package:
{
"name": "any name :D",
"version": "3.2.0",
"nameVersion": "",
"descriptionVersion": "",
"engines": {
"node": "14.15.0"
},
"description": ":D",
"main": "src/index.js",
"scripts": {
"start": "node ."
},
"author": "",
"license": "",
"dependencies": {
"discord.js": "^12.5.1",
"express": "^4.17.1"
}
}
as you can see, there are two more keys, nameVersion & descriptionVersion.. I thought it would be nice to leave them with the version, which comes with it when I put npm init..
But a question came to me, is there a problem if I put something that is normally npm? like, even if no error, is it a bad practice? Or am I just traveling? well, i tested it and it works fine, but i'm still thoughtful about it..

It's probably okay to have additional properties, although it would probably be good to have any additional properties grouped together under a single key. Many JS libraries also use additional properties for example ESLint uses "eslintConfig", etc. in package.json: https://eslint.org/docs/user-guide/configuring#using-eslintignore-in-packagejson

Related

Why can I no longer minify my Javascript files?

I am using VS Code to maintain a Javascript library I created and I used Google Closure Compiler (CC) to minify the js file. I have made some changes to the original code but although CC executes without any warning/error messages it fails to create the output file.
This is the package.json file
{
"name": "canvas-gui",
"version": "1.0.0",
"description": "On canvas GUI for p5.js",
"main": "main.js",
"scripts": {
"tsc": "tsc",
"typedoc": "npx typedoc",
"gcc": "npx google-closure-compiler src_js --js_output_file dist/lib/gui.min.js --language_in ECMASCRIPT_2020 --language_out ECMASCRIPT_NEXT"
},
"keywords": [
"GUI",
"canvas",
"p5.js"
],
"author": "Peter Lager",
"license": "MIT",
"devDependencies": {
"#types/p5": "^1.4.2",
"google-closure-compiler": "^20220803.0.0",
"p5": "^1.4.2",
"typedoc": "^0.23.10",
"typescript": "^4.7.4"
}
}
I researched on the parameter values here and tried changing the source parameter to
--js src/**.js
--js='src_js/**.js'
src_js/canvas_gui.js
--js src_js/canvas_gui.js
--js='src_js/canvas_gui.js'
all without success.
I also set the warning level to VERBOSE but still no messages.

Server running error in parcel by starting the external file index.html I Ignoring the main but it also doesn't work(Build Failed)

[Build Error in parcel # 2.7.0 start when I am trying to add external index.html file in the main I also ignored the main but it also doesn't work for me. Will please someone help me to solve this problem It also not working with JavaScript file when I added externally and also getting error with html file but I want to add the html file but as a solution I try to add JavaScript file but it also doesn't work for me. Will please someone solve this issue or tell me how to solve this issue
{
"name": "forkify",
"version": "1.0.0",
"description": "",
"main": "unrelated.js",
"targets": {
"main": false
},
"scripts": {
"start": "parcel start index.html",
"build": "parcel build index.html"
},
"author": "Meelad Sultan",
"license": "ISC",
"devDependencies": {
"parcel": "^2.7.0"
}
}
enter code here
At last I can find the solution of my problem after almost a day if someone else facing the same problem they just do add the **Browsers list ** in the package.json file before script and ignore the main target and also set the parcel to latest then the parcel will run successfully and do not give any server error or build error. And don't forget to run periodically npx browerlist#latest --update-db. It will update your package-lock file with new caniuse-lite version. In this case, you will be sure that last two version or > 0.2% will target what you expect
{
"name": "forkify",
"version": "1.0.0",
"description": "",
"main": "unrelated.js",
"target": {
"main": false
},
"browserslist": "> 0.5%, last 2 versions, not dead",
"scripts": {
"start": "parcel index.html "
},
"author": "Meelad Sultan",
"license": "ISC",
"devDependencies": {
"#parcel/transformer-sass": "^2.7.0",
"parcel": "latest"
},
"dependencies": {
"sass": "^1.55.0"
}
}

cant get ES modules to work with import or require

I'm building a command line based application and was using require to link various files and node modules. I have previously used Require with no issues and now I get nothing but errors.
Error with Require:
Error [ERR_REQUIRE_ESM]: require() of ES Module ./lib/departments.cjs not supported,
Instead change the require of inquirer.js in ./lib/departments.cjs to a dynamic import() which is available in all CommonJS modules.
After this I tried multiple methods to get it to work again, but had no luck so I tried to switch to import. When I switched to import I got this message:
SyntaxError: Cannot use import statement outside a module
Ive tried to add type: "module" to my package.json file, but I don't know if I am putting it in the wrong place or what.
My JSON file looks like this
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "server.js",
"directories": {
"lib": "lib"
},
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "git+https://.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://issues"
},
"homepage": "https://#readme",
"dependencies": {
"console.table": "^0.10.0",
"dotenv": "^16.0.2",
"express": "^4.18.1",
"inquirer": "^9.1.1",
"mysql2": "^2.3.3",
"node-fetch": "^2.6.7"
}
}
Seems like you are using .cjs extension for your js file, cjs is a commonJS file which doesn't support import. You need to use a dynamic import.
It's worth mentioning that ES modules cannot be imported using the require() function of cjs.

Error - git push heroku master

If you're attempting to help me, I really appreciate it.
So when I write git push heroku master, it fails to parse, and before you spit at me and say 'READ OTHERS!!!!' I have. I've rewritten the package.JSON and used a validator. The strange thing is it always says line 9, column 3, every time I reformat the package.JSON, always line 9, column 3. I have changed over 5-7 times. I don't think my package.json is necessary as it always brings that error.
But here it is anyway.
{
"name": "vulture",
"version": "1.0.1",
"description": "Vulture is a bot for discord.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
"node": "8.4.0",
"npm": "5.4.0"
},
"author": "swagehsaan840#0336",
"license": "MIT"
}
A side note is changing it will probably give me the same error, but I never know, after using a validator and changing any times, it always says line 9, column 3.
Thanks anyway! :)
try to write this way package.json
{
"name": "vulture",
"version": "1.0.0",
"description": "vulture",
"main": "index.js",
"private": true,
"scripts": {
"start": "node index.js",
},
"author": "vulture",
"license": "ISC",
"dependencies": {
"node": "8.4.0",
"npm": "5.4.0"
}
}
add Buildpacks in heroku goto setting select add Buildpacks --> select nodejs

Why do we need to use package.json? [duplicate]

This question already has answers here:
What are the main uses for the NPM package.json file?
(2 answers)
Closed 6 years ago.
I am trying to learn web socket with JavaScript to this site, but I do not understand something that why I need to use package.json. This is my package.json file code:
`{
"name": "module-name",
"version": "10.3.1",
"description": "An example module to illustrate the usage of a package.json",
"author": "Your Name <you.name#example.org>",
"contributors": [{
"name": "Foo Bar",
"email": "foo.bar#example.com"
}],
"bin": {
"module-name": "./bin/module-name"
},
"scripts": {
"test": "vows --spec --isolate",
"start": "node index.js",
"predeploy": "echo im about to deploy",
"postdeploy": "echo ive deployed",
"prepublish": "coffee --bare --compile --output lib/foo src/foo/*.coffee"
},
"main": "lib/foo.js",
"repository": {
"type": "git",
"url": "https://github.com/nodejitsu/browsenpm.org"
},
"bugs": {
"url": "https://github.com/nodejitsu/browsenpm.org/issues"
},
"keywords": [
"nodejitsu",
"example",
"browsenpm"
],
"dependencies": {
"primus": "*",
"async": "~0.8.0",
"express": "4.2.x",
"winston": "git://github.com/flatiron/winston#master",
"bigpipe": "bigpipe/pagelet",
"plates": "https://github.com/flatiron/plates/tarball/master"
},
"devDependencies": {
"vows": "^0.7.0",
"assume": "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0",
"pre-commit": "*"
},
"preferGlobal": true,
"private": true,
"publishConfig": {
"registry": "https://your-private-hosted-npm.registry.nodejitsu.com"
},
"subdomain": "foobar",
"analyze": true,
"license": "MIT"
}`
But I do not understand why I need to use it. I tried to find on google but can not find something useful. One more thing, if I create package.json then why I need to write dependencies?
You do not NEED package.json. However, you will most likely want it. As you make larger applications using node.js, you will find that using other people's code is the best solution vs. writing the same thing yourself.
npm has lots of packages that people want to use over and over again. package.json provides a simple way for people to keep track of packages they use in their application.

Categories

Resources