problems with including dependencies in package.json - javascript

Why is it that when including dependencies in package.json such as
"dependencies": {
"nodemailer": "*"
}
and running
npm install
doesn't install the package but doing
npm install nodemailer
is ok?
in both instances, the message returned was
WARN Invalid name: "try node mailer"
WARN email No description
WARN email No repository field
WARN email No README field
WARN email No license field
but only in the second instance the node_modules directory is populated with the package

I'd suggest that you use some of the other version matching ranges and avoid the asterix one,, as per specs #page: https://docs.npmjs.com/files/package.json#dependencies
I did it fine with this one:
{
"name": "test",
"version": "1.0.0",
"description": "my test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"nodemailer": "~2"
},
"author": "",
"license": "ISC"
}
hope that helps you

Rather than using a wildcard, you can try "" instead. Otherwise this seems to be working:
{
"name": "testr",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"nodemailer": "^4.0.1"
},
"author": "",
"license": "ISC"
}

Related

How to make an installer for your electron app

So I'm trying to make an installer from the end of this video https://www.youtube.com/watch?v=TnXz_nnQZrw for my electron app but I get an error and it doesn't help me at all
Here is my package.json
{
"name": "second-electron-attempt",
"productName": "CPU Monitoring",
"version": "1.0.2",
"description": "A great cpu monitoring tool",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\"",
"build-installer": "electron-builder"
},
"build": {
"appId": "com.nickos.app",
"win": {
"target": "NSIS",
"icon": "src/fraggaros.png",
"requestedExecutionLevel": "requireAdministrator"
},
"nsis": {
"installerIcon": "src/fraggaros.png",
"uninstallerIcon": "src/fraggaros.png",
"uninstallDisplayName": "CPU Monitor",
"license": "license.txt",
"oneClick": false,
"allowToChangeInstallationDirectory": true
}
},
"keywords": [],
"author": {
"name": "NickVelos420",
"email": "velosn#gmail.com"
},
"license": "MIT",
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"name": "second_electron_attempt"
}
},
{
"name": "#electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "#electron-forge/maker-deb",
"config": {}
},
{
"name": "#electron-forge/maker-rpm",
"config": {}
}
]
}
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"os-utils": "0.0.14"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.54",
"#electron-forge/maker-deb": "^6.0.0-beta.54",
"#electron-forge/maker-rpm": "^6.0.0-beta.54",
"#electron-forge/maker-squirrel": "^6.0.0-beta.54",
"#electron-forge/maker-zip": "^6.0.0-beta.54",
"electron": "12.0.2",
"electron-builder": "^22.10.5"
}
}
And this is the error
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! second-electron-attempt#1.0.2 build-installer: `electron-builder`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the second-electron-attempt#1.0.2 build-installer script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
It says that there is additional logging above but this is what is above
https://i.stack.imgur.com/ruXXC.png
If anyone knows please answer with some code or a great tutorial. btw I've searched on google but there is nothing that tells you how to make an installer for electron. Thank you!

import { pipe } from "lodash/fp" gives 'ERR_UNSUPPORTED_DIR_IMPORT' error

I was trying to import pipe from lodash/fp
import { pipe } from "lodash/fp";
But getting following errors
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/home/user/Codes/redux-tut/node_modules/lodash/fp' is not supported resolving ES modules imported from /home/user/Videos/Codes/redux-tut/src/index.js
Did you mean to import lodash/fp.js?
at finalizeResolution (internal/modules/esm/resolve.js:267:17)
at moduleResolve (internal/modules/esm/resolve.js:668:10)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:758:11)
at Loader.resolve (internal/modules/esm/loader.js:100:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:246:28)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:47:40)
at link (internal/modules/esm/module_job.js:46:36) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///home/user/Videos/Codes/redux-tut/node_modules/lodash/fp'
}
My package.json file is
{
"name": "redux-tut",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"lodash": "^4.17.20"
}
}
This solved it for me:
import pipe from "lodash/fp/pipe.js";

npm start not picking up updated package.json

I am writing a node app from scratch, with the following package.json, which is pretty boiler-plate.
{
"name": "myfirstnodeproject",
"version": "1.0.1",
"description": "Learning node",
"main": "index.js",
"start": "node server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC",
"dependencies": {
"request": "^2.88.2"
}
}
I created server.js to look like this:
var http = require("http");
http.createServer((inRequest, inResponse) => {
inResponse.end("Your IP Address is " + inRequest.connection.remoteAddress);
}).listen(9000);
When I started the app using npm start, it worked fine.
Then, I created a new file called server_time.js:
require("http").createServer((inRequest, inResponse) => {
const requestModule = require("request");
requestModule(
"http://worldtimeapi.org/api/timezone/America/New_York",
function (inErr, inResp, inBody) {
inResponse.end(
`Hello from my first Node Web server: ${inBody}`
);
}
);
}).listen(9000);
I changed the following line in my package.json:
"start": "node server_time.js",
However, Node still seems to pick up server.js instead. I tried npm cache verify, npm cache clear --force, rm -rf node_modules, rm package-lock.json, and npm install again, but the problem didn't seem to go away. I even removed package.json and redefined it, but the value of start when I call npm start is still stale.
Here's an output from my shell:
GsMacbookPro:MyFirstNodeProject g$ cat package.json
{
"name": "myfirstnodeproject",
"version": "1.0.1",
"description": "Learning node",
"main": "index.js",
"start": "node server_time.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "G",
"license": "ISC",
"dependencies": {
"request": "^2.88.2"
}
}
GsMacbookPro:MyFirstNodeProject g$ ls
node_modules package-lock.json package.json server.js server_time.js
GsMacbookPro:MyFirstNodeProject g$ npm start
> myfirstnodeproject#1.0.1 start /Users/g/Repos/MyFirstNodeProject
> node server.js
Before someone asks, node version is v10.16.3, and npm version is 6.9.0.
The reason why npm start currently works for you is because npm will default some script values based on package contents.
If there is a server.js file in the root of your package, then npm will default the start command to node server.js.
See here:
npm.js - default values
So your start field inside package.json wasn't actually doing anything because it was not under scripts, which is where it should belong.
The correct approach is to update your package.json so that it looks like the following:
{
"name": "myfirstnodeproject",
"version": "1.0.1",
"description": "Learning node",
"main": "index.js",
"scripts": {
"start": "node server_time.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "G",
"license": "ISC",
"dependencies": {
"request": "^2.88.2"
}
}
Try:
{
"name": "myfirstnodeproject",
"version": "1.0.1",
"description": "Learning node",
"main": "server_time.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server_time.js"
},
"license": "ISC",
"dependencies": {
"request": "^2.88.2"
}
}
and then npm run start.

'console' is 'undefined in the shell by using webpack with node.js

I have a file my-script.js that only returns this:
console.log('Hi I'm working')
When I type in shell only
node my-script.js
This works successfully.
But I'd like it to work too when I typed in just this:
npm start
How to make it work?
Because it is generating an error message:
Line: 1 Error: console is undefined Code: 800A1391 Source: Microsoft
JScript runtime error
I have a package.json file that points to this file to be the start but this is not resolving.
Here is my package.json file:
{
"name": "my-app",
"version": "1.0.0",
"main": "my-script.js",
"scripts": {
"start": "my-script.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"webpack-dev-server": "^3.9.0"
},
"devDependencies": {
"webpack": "^4.41.2"
},
"description": ""
}
Use node in start script
{
"name": "my-app",
"version": "1.0.0",
"main": "my-script.js",
"scripts": {
"start": "node my-script.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"webpack-dev-server": "^3.9.0"
},
"devDependencies": {
"webpack": "^4.41.2"
},
"description": ""
}

npm gulp 800a138f javascript error

When i put 'gulp hello' in cmd i got this error 800a138f javascript object expected error
This is my package.json file
`{
"name": "goes",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node gulp.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "^3.9.1"
}
}`
This is gulp.js
`var gulp = require('gulp');
gulp.task('hello', function() {
console.log('Hello Zell');
});`

Categories

Resources