Javascript package import cannot find package - javascript

I am glad to share my first npm package eulejs. Since I need to test it, I found that the command npm link bind locally the package on another NodeJS project. Great! HOWEVER, I was not able to import it as a package in this way. Sad...
I published the package and made a minimal project. The src/index.js code is below:
import euler from "eulejs";
const diagram = euler({
a: [1, 2, 3],
b: [2, 3, 4],
c: [3, 4, 5],
d: [3, 5, 6],
});
/* Euler dictionary:
* {
* 'a,b': [2],
* 'b,c': [4],
* 'a,b,c,d': [3],
* 'c,d': [5],
* 'd': [6],
* 'a': [1]
* }
*/
console.log(diagram);
For installation:
Create and go to folder with command mkdir ~/eulejs-example && cd eulejs-example;
Create a file package.json with content below:
{
"name": "eulejs-example",
"description": "Example for package eulejs",
"type": "module",
"version": "0.0.0",
"scripts": {
"start": "nodemon ./src/index.js",
"test": "echo \"Not implemented\""
},
"keywords": [
"jest"
],
"author": "brunolnetto",
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.20"
},
"dependencies": {
"eulejs": "^1.0.2"
}
}
Install dependencies with the command run npm install;
Run the command npm start.
A similar error log appears:
[nodemon] starting `node ./src/index.js`
node:internal/errors:484
ErrorCaptureStackTrace(err);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '/home/brunolnetto/github/alloyha/experiments/web/eulejs-MVP/node_modules/eulejs/' imported from /home/brunolnetto/github/alloyha/experiments/web/eulejs-MVP/src/index.js
at new NodeError (node:internal/errors:393:5)
at legacyMainResolve (node:internal/modules/esm/resolve:235:9)
at packageResolve (node:internal/modules/esm/resolve:847:14)
at moduleResolve (node:internal/modules/esm/resolve:909:20)
at defaultResolve (node:internal/modules/esm/resolve:1124:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v18.12.1
[nodemon] app crashed - waiting for file changes before starting...
It would be very nice to have a feedback on how to solve such issue.

Related

NODE & ELECTRON No valid versions available for electron-navigation

i tried to build a open source "Browser that allow flash player"
My problem is, when i use "npm install"
it's return me this error:
npm ERR! code ENOVERSIONS
npm ERR! No valid versions available for electron-navigation
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\rstei\AppData\Roaming\npm-cache\_logs\2021-08-18T13_30_37_799Z-debug.log
My package.json:
{
"name": "Misaki",
"productName": "Flash Browser",
"description": "Electron Browser For Games",
"homepage": "https://www.flashbrw.com",
"author": "Misaki",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "electron .",
"publish": "electron-builder --win -p always",
"build": "electron-builder --win"
},
"license": "ISC",
"devDependencies": {
"electron": "^9.0.5",
"electron-builder": "22.9.1"
},
"dependencies": {
"electron-navigation": "^1.5.8",
"electron-updater": "4.3.5"
},
"build": {
"appId": "com.flashbrw.app",
"extraResources": [
"./plugins/**"
],
"directories": {
"buildResources": "resources",
"output": "release"
},
"publish": [
{
"provider": "github",
"owner": "asteroid-dev",
"repo": "FlashBrowser"
}
],
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64",
"ia32"
]
}
]
},
"nsis": {
"installerIcon": "icon.ico",
"uninstallerIcon": "icon.ico",
"uninstallDisplayName": "Flash Browser",
"oneClick": true,
"perMachine": false,
"artifactName": "FlashBrowser.${ext}"
}
}
}
if you want see the open source: https://github.com/asteroid-dev/FlashBrowser
Thanks in advance for someone can find a way for fix it !
Your project specifies a non-existent version of the electron-navigation module.
Your package.json calls for "electron-navigation": "^1.5.8". The version specifier, ^1.5.8, permits any version greater than or equal to 1.5.8 and below 2.0.0.
However, it appears the only available version of that package is version 6.6.6. You can confirm this from the command line:
$ npm show electron-navigation versions
6.6.6
The specifier ^1.5.8 does not accept 6.6.6.
I can only guess why your project is asking for such a precise but non-existent version. Change the specifier to ^6.6.6, and it should install fine.

Is my JSON file being formatted properly?

package.json:
{
"name": "password-generator",
"productName": "Password Generator",
"version": "1.0.0",
"description": "Password generator desktop app",
"main": "main.js",
"scripts": {
"start": "electron ."
"build-installer": "electron-builder"
},
"build": {
"appId": "password-generator",
},
"win": {
"target": ["nsis"],
"icon": "/icon.png",
},
"nsis": {
"installerIcon": "/icon.png",
"uninstallerIcon": "/icon.png",
"uninstallDisplayName": "Password Generator",
"oneClick": false,
"allowToChangeInstallationDirectory": true,
},
"author": "JipBit",
"license": "ISC",
"devDependencies": {
"electron-forge": "^5.2.4",
},
"dependencies": {
"electron-builder": "^22.7.0",
},
}
Error:
npm ERR! code EJSONPARSE
npm ERR! file C:\Users\mel\Desktop\Password Generator\package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 212 while parsing '{
npm ERR! JSON.parse "name": "password-generator",
npm ERR! JSON.parse "pro'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
Information: When attempting to run npm start and npm run build-installer, I get this error about my package.json file. I got this error after adding on to my package.json while setting up to run the build-installer to make my electron app an executable.
Edit of new error:
'electron' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! password-generator#1.0.0 start: `electron .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the password-generator#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Initially looking at it, you need a ',' on line 8 after:
"start": "electron ."
EDIT:
Try this, there are just a few misplaced commas:
{
"name": "password-generator",
"productName": "Password Generator",
"version": "1.0.0",
"description": "Password generator desktop app",
"main": "main.js",
"scripts": {
"start": "electron .",
"build-installer": "electron-builder"
},
"build": {
"appId": "password-generator"
},
"win": {
"target": ["nsis"],
"icon": "/icon.png"
},
"nsis": {
"installerIcon": "/icon.png",
"uninstallerIcon": "/icon.png",
"uninstallDisplayName": "Password Generator",
"oneClick": false,
"allowToChangeInstallationDirectory": true
},
"author": "JipBit",
"license": "ISC",
"devDependencies": {
"electron-forge": "^5.2.4"
},
"dependencies": {
"electron-builder": "^22.7.0"
}
}
Hi you have many coma mistakes.
Use this page to correct your JSON :
https://codebeautify.org/jsonviewer
Here is your JSON corrected :
{
"name": "password-generator",
"productName": "Password Generator",
"version": "1.0.0",
"description": "Password generator desktop app",
"main": "main.js",
"scripts": {
"start": "electron .",
"build-installer": "electron-builder"
},
"build": {
"appId": "password-generator"
},
"win": {
"target": ["nsis"],
"icon": "/icon.png"
},
"nsis": {
"installerIcon": "/icon.png",
"uninstallerIcon": "/icon.png",
"uninstallDisplayName": "Password Generator",
"oneClick": false,
"allowToChangeInstallationDirectory": true
},
"author": "JipBit",
"license": "ISC",
"devDependencies": {
"electron-forge": "^5.2.4"
},
"dependencies": {
"electron-builder": "^22.7.0"
}
}

Eslint Jsdoc Plugin is not exectued

I am trying to run the ESLint JSDoc plugin
When I run npx eslint . airbnb rules are enforced but not the jsdoc ones requiring to add JSDoc.
Am I missing something ?
Here is a test repo
package.json
{
"name": "eslint-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "^6.7.2",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jsdoc": "^18.4.3"
}
}
index.js
const fn = (a) => {
console.log('a :', a);
return a;
};
module.exports = { fn };
You are missing the ESLint configuration file. Add .eslintrc.js to the root of your project. Then copy the following basic configuration:
module.exports = {
root: true,
plugins: ['jsdoc', 'import'],
extends: [
'eslint:recommended',
'plugin:jsdoc/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'airbnb-base'
]
}
See Configuring ESLinf for more informaion.

webpack 2.6.2, javascript

I've been trying to follow the simplest example on how to set up a minimal react app with webpack... but i can't seem to get the webpack-dev-server to work.. i've tried alot of suggestions here and they dont seem to work. i started off with webpack 3.-.- version and now changed to webpack 2.6.2 still same issue.
this is my package.json file:
{
"name": "react-tutorial",
"version": "1.0.0",
"description": "app to learn how to make react apps",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified...leave no be by force to test\" && exit 1",
"start": "webpack-dev-server --hot"
},
"repository": {
"type": "git",
"url": "git+https://github.com/davidsbelt/react-tutorial.git"
},
"author": "Chuka-ogwude David",
"license": "ISC",
"bugs": {
"url": "****"
},
"homepage": "****",
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
"devDependencies": {
"webpack": "^2.3.2",
"webpack-dev-server": "^2.4.2"
}
}
this is the webpack.config.js file:
var config = {
entry: './index.js',
output: {//make sure to install
path: '/',
filename: 'bundle.js'
},
devServer: {
inline: true,
port: 8080
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
}
}
module.exports = config
and this is the error i get when i run npm start:
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API sche
ma.
- configuration.entry should be one of these:
object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
The entry point(s) of the compilation.
Details:
* configuration.entry should be an object.
* configuration.entry should be a string.
* configuration.entry should NOT have duplicate items (items ## 1 and 3 are identical) ({
"keyword": "uniqueItems",
"dataPath": ".entry",
"schemaPath": "#/definitions/common.nonEmptyArrayOfUniqueStringValues/uniqueItems",
"params": {
"i": 3,
"j": 1
},
"message": "should NOT have duplicate items (items ## 1 and 3 are identical)",
"schema": true,
"parentSchema": {
"items": {
"minLength": 1,
"type": "string"
},
"minItems": 1,
"type": "array",
"uniqueItems": true
},
*********
* configuration.entry should be an instance of function
function returning an entry object or a promise..
"
all my files (index.js, App.js, index.html, webpack.config.js, package.json) are in the same directory...
Please help... this seemingly straightforward configuration has cost me a lot of hours.
Thanks...
It looks like you're running a configuration file that matches with webpack the older version 1. In particular, the module.loaders statement no longer exist in webpack > 2, and has been replaced with module.rules see :
https://webpack.js.org/guides/migrating/#module-loaders-is-now-module-rules
Note that there are less changes when migrating from webpack 2 to 3, so I guess the migration guide will be helpful in your case.
Hope this helps!
Strange, I was not able to reproduce your problem with your webpack.config.js file. However, modifying the entry line to the following dumps the same error message :
entry:
[
"./index.js",
"webpack/hot/dev-server",
],
Are you sure you're using the right webpack config file here ? Hope this will help you fix the issue.
Note, on my system, I have webpack#2.7.0, webpack-dev-server#2.8.2

How do you run multiple grunt scripts.postinstall?

I'm trying to run multiple CLI commands from scripts.postinstall of grunt. I can't figure out how to get both to run. If I add the second command neither run. Separately they both work on postinstall and in the console.
I've tried wrapping them in an array:
"scripts": {
"postinstall": ["node_modules/.bin/bower install", "grunt setup"]
},
I tried separating them with a semi-colon:
"scripts": {
"postinstall": "node_modules/.bin/bower install; grunt setup"
},
I can't seem to find the solution on NPM Scripts
My gruntfile.js for these sections look like this:
mkdir: {
setup: {
options: {
create: [
'app/main/source/www', 'app/main/build', 'app/main/docs', 'app/main/tests',
'app/development',
'app/releases'
]
}
}
}
grunt.registerTask('setup', [
'mkdir:setup',
'bowercopy:wordpress'
]);
In case it helps here's a parred down version of my package.json that I snipped the above code examples, mostly to provide context.
{
"name": "webapp",
"version": "0.1.0",
"description": "A web app using bower and grunt",
"main": "gruntfile.js",
"scripts": {
"postinstall": "node_modules/.bin/bower install"
},
"repository": {
"type": "git",
"url": "someurl.com"
},
"keywords": [
"web", "app"
],
"author": {
"company": "somecompany",
"name": "somename",
"email": "email#me.com"
},
"license": "MIT",
"homepage": "https://someurl.com",
"bugs": {
"url": "someurl.com"
},
"devDependencies": {
"grunt": "^0.4.5",
"bower" : "~1.3.5",
etc
}
}
You can use && to run multiple commands in the npm scripts section
"scripts": {
"postinstall": "bower install && grunt setup"
},
You could try writing a Bash script that executes those two commands and run that instead.
post_install.sh:
#!/bin/bash
node_modules/.bin/bower install
grunt setup
package.json:
"scripts": {
"postinstall": "./post_install.sh"
},

Categories