Node NPM unable to require package by name only path - json

I created a new Node Package to start sharing a project that I'm working on, but I'm having a bit of trouble getting my require statement to work.
Project: https://github.com/kcjonson/indigo
The issue that I'm having is that requiring my module this way:
var indigo = require('indigo');
Does not work, but requiring it by more explicit path like:
var indigo = require('indigo/lib/indigo');
works just fine.
I assume this is an issue with my package.json file which is as follows:
{
"author": {
"name": "Kevin Jonson",
"email": "kcjonson#gmail.com",
"url": "http://kevinjonson.com"
},
"name": "indigo",
"description": "Node.js Facade for Perceptive Home Automations Indigo home automation servers python REST API",
"version": "0.0.7",
"repository": {
"type": "git",
"url": "git://github.com/kcjonson/indigo.git" },
"directories": {
"lib": "./lib"
},
"main:": "lib/indigo.js",
"license": "MIT",
"private": false
}
I've successfully added it to NPM and running npm install on the project that is using it does download the correct latest version and places it in the node_modules directory as expected.
Any help would be appreciated, thanks in advance.

I am not sure if that is going to work but still worth a try I guess.
Try removing 'directories'

Related

mysql node module give me an error "require is not defined"

I'm trying to use mysql module in a node js project (node 18.12, mysql 2.18.1)
in my project I must use
"type": "module"
in my package.json because the app is constructed with modules. for example i use this imports in the head of my app.js
import { createServer } from 'node:http';
import fs from 'node:fs/promises';
import { createTodo, findTodos } from './functions/storage.js';
import { index,create } from './functions/api/api.js';
then I add the line, like in the doc
var mysql = require('mysql');
but when I launch the app i have this error
mysql node module "require is not defined in ES module scope, you can
use import instead"
I have tried to change type to commonjs but get the same error in the other way, tried to change the extensions of the js file for cjs or mjs . every time same type of error.
How can I use mysql with "native" module node app ?
I'm a beginner in node so, sorry if it is a dumb question, but I can't find any answer by the web.
Here is my package.json
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"keywords": [],
"author": "",
"license": "ISC",
"volta": {
"node": "18.12.1"
},
"dependencies": {
"mysql": "^2.18.1"
}
}
Try to remove "type":"module" from package.json.
From How to fix reference error require is not defined in javascript
I finally found the answer here
const require = createRequire(import.meta.url);
var mysql      = require('mysql');
I hope this will be useful for other people ;)

vscode extension [tht13.python]: 'configuration.jsonValidation.url'

I got this error notification while using VSCode:
[tht13.python]: 'configuration.jsonValidation.url' must be
an absolute URL or start with './' to reference
schemas located in the extension.
I have found and changed jsonValidation to:
"jsonValidation": [
{
"fileMatch": ".condarc",
"url": "./schemas/condarc.json"
},
{
"fileMatch": "environment.yml",
"url": "./schemas/conda-environment.json"
},
{
"fileMatch": "meta.yaml",
"url": "./schemas/conda-meta.json"
}
]
in package.json, but it still doesn't work.
How to figure out this issue?
You are using the extension "Python for VSCode" (tht13.python). It looks like this extension is not maintained anymore (last commit on Jun 13, 2018)
Maybe you should switch to another extension. I'm quite happy with the "Python" (ms-python.python) extension from Microsoft https://marketplace.visualstudio.com/items?itemName=ms-python.python

Opening a html file in the browser from npm script

All I can find for this are solutions that require installing an npm package that will start up an http server for hosting the file. My only requirement however is opening a very simple generated html file from the local computer into the browser via a npm script, no server required, is this doable without a package?
I tried the Daniel's answer, but it does not works to me.
Based on his answer, I found the open-cli package.
npm i -D open-cli
and use it (open-cli) in package.json script object like so
{
"name": "somename",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"open-my-html": "open-cli path/to/your/index.html",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies: {
"open-cli": "^6.0.1"
},
"author": "",
"license": "ISC"
}
then run
npm run open-my-html
Now it works opening the html file on default browser.
Found that I could create a bash script with contents
#!/bin/bash
start chrome "$(realpath "./jest/report.html")"
And then run that using
"test": "jest && bash ./open-browser.sh"
Supposing that your node script and index.html are in the same folder
const open = require('open');
(async () => {
await open('index.html', {"wait": true });
})();
Take a look at this package: https://www.npmjs.com/package/open
the easiest way to do this is to install the open package
npm i open --save-dev
and use it in package.json script object like so
{
"name": "somename",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"open-my-html": "open path/to/your/index.html",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies: {
"open": "^7.3.0"
},
"author": "",
"license": "ISC"
}
then run
npm run open-my-html
{ "start": "start http://localhost:8000 & npm run dev", }
just use above script this works for me. first it will open url in browser and then launch the server. issue is first url will throw error and then after runing sever page wil be auto reload.
This is better if you dont need to use any external package.

How do you make manifest.json for Microsoft Teams bot?

I followed the online tutorial for constructing a bot in Visual Studio and deploying it Azure, and so far that seems to have worked. Now I want to add this bot to Microsoft Teams via the "Sideload a bot or tab" method. The online tutorial has NO explanation for what I need to do so I need some help. Here is the manifest.json I was currently trying to upload in a zip folder. Please help, I don't know how this process works.
{
"$schema": "https://statics.teams.microsoft.com/sdk/v1.0/manifest/MicrosoftTeams.schema.json",
"manifestVersion": "1.0",
"version": "1.0.0",
"id": "a5db14e6-8adf-445b-a0aa-daadc5e155eb",
"packageName": "com.testbot20170525114049",
"developer": {
"name": "Megan",
"websiteUrl": "https://website.com/",
"privacyUrl": "https://website.com/privacy",
"termsOfUseUrl": "https://website.com/app-tos"
},
"name": {
"short": "Botty"
}
"description": {
"short": "A sample bot to test the bot upload process"
}
"bots": [
{
"botId": "a5db14e6-8adf-445b-a0aa-daadc5e155eb",
"needsChannelSelector": "true",
"scopes": [ "team", "personal" ]
}
]
}
Enable Public Developer Preview. The v1.0 manifest is fully supported in that mode, and while it may work in the public version, for now I'd switch to developer preview mode.
Make sure your manifest follows the v1.0 format. While your schema is close, there are a few required fields missing:
description.full
icons.outline
icons.color (note currently there is a 2k limit on file size)
accentColor
Zip the manifest and icons into a sideloadable package. Make sure the manifest.json is at the top level.
Follow the sideload instructions.

Node package manager keeps on loading in installing package depenencies

I am studying node js and I created a package.json like this:
{
"name": "NodeExpress",
"version": "0.1.0",
"description": "My Simple Express",
"main": "app.js",
"author": {
"name": "My Name",
"email": "name#email.com"
},
"dependencies": {
"express": "*",
"jade": "*",
}
}
When I checked my node_modules it has all the dependencies I need but in my console it's just loading. What does it mean? Is it still downloading?
When I checked the time it is almost 20 minutes past away since I install the dependencies.
Is it fine if I stop the execution of node packager installer?