IntelliJ and WebStorm treating npm linked local module as an indirect dependency, and not using it in it's suggestions - node.js

I have a local node module I am trying to reuse in my other modules.
I use npm link to add the module as a dependency to other modules.
Everything works fine, however IntelliJ Treats this as an indirect dependency even if I add the dependency to the pom. Because of this none of the autocompletions for the dependency work.
Pom1:
{
"name": "test-module",
"version": "1.0.0",
"description": "\"Module functionality testing project\"",
"main": "index.js",
"scripts": {
"test": "\"No Tests done\""
},
"author": "",
"license": "ISC"
}
pom2:
{
"name": "test-module-2",
"version": "1.0.0",
"description": "\"Module functionality testing project\"",
"main": "index.js",
"scripts": {
"dev": "node index.js",
"test": "\"No Tests done\""
},
"author": "",
"license": "ISC",
"dependencies": {
"test-module": "^1.0.0"
}
}
Anyone know why this is and how to fix it?

The issue is tracked at WEB-49242, please follow it for updates.
As a workaround, please try including node_modules\test-module folder in index by selecting Mark directory as/Cancel exclusion from its right-click menu

Related

Parcel showing ENOENT: no such file or directory error when I save my html

beginner web dev here, first time using parcel and sass.
So, I have the parcel set up, but when I change and save the src/index.html, terminal shows me this error, instead of changing the dist/index.html.
It is very weird because in the error, there is supposed to be a file called dist/index.html.9424.5, which really does not exist in my case.
Here is my package.json set up:
{
"name": "calculator_project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "parcel src/index.html",
"build": "parcel build src/index.html"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#parcel/transformer-sass": "^2.7.0",
"parcel": "^2.7.0",
"sass": "^1.55.0"
}
}
Also, this is my folder structure and html
I will be very thankful for any tips or solutions.
Also, I am very sorry if I documented this error incorrectly, I am still pretty new to this.
Thanks for reading and help!

Find unused modules in nodeJS outside package.json

I have to document and resume code from another developer which has been fired because of a lot a disciplinary trouble inside the team.
The application uses nodeJS and mongoDB and I'm a beginner at nodeJS, but webstorm help me a lot to understand how the application works.
(I precise the former dev did not leave me so much documentation, so I'm doing reverse engeeniring and cleaning here).
My question today is:
the node_modules looks like it is really huge to me, with 243 sub-repository. I'm suspecting than some of these are not usefull to the project but the package.json is not really helping here:
{
"name": "my_rotting_project",
"version": "1.0.0",
"description": "",
"main": "main.js",
"bin": "main.js",
"scripts": {
"start": "node --no-deprecation core/server",
"server": "nodemon --no-deprecation core/server",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"luna": "file:./core"
},
"pkg": {
"scripts": "plugins/**/*.js",
"assets": [
"static/**/*",
"core/static/**/*"
]
},
"nodemonConfig": {
"ext": "js,mjs,json,html,css,ejs"
}
}
I have launched npx check and npx npm_check commands but they show me no unused library which seems unlikely (but both of them have written than some of dependencies was missing in package.json)
Does someone know if theses plugins are reliable enough or should I try other methods ? (and what should I do in this case ?)
thank you !

Heroku: Bunch of npm errors on deployment

I have a bunch of npm errors in my heroku logs. How can I begin to debug this? thanks!
screenshot
package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": "8.1.1",
"npm": "5.0.3"
},
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.0"
}
}
NPM ERR: missing script: start
It seems like you're missing the "start" script in your package.json file. That's where I would start looking. Heroku might assume you've set this script up beforehand. Here's a sample package.json file with the start script:
{
"name": "your-app",
"version": "1.0.0",
"main": "index.js",
"scripts": { // your npm scripts go here
"start": "nodemon index.js", // or whatever server package you're using
"lint:js": "node_modules/eslint/bin/eslint.js ./ ./**/*.js --fix; exit 0",
"lint:css": "node_modules/csslint/cli.js public/css/; exit 0",
"test": "NODE_ENV=test node_modules/mocha/bin/mocha"
},
"more": "settings below"
}
Here's a blurb from the Heroku website:
Specifying a start script
To determine how to start your app, Heroku first looks for a Procfile. If no Procfile exists for a Node.js app, we will attempt to start a default web process via the start script in your package.json.
The command in a web process type must bind to the port number specified in the PORT environment variable. If it does not, the dyno will not start.
For more information, see Best Practices for Node.js Development and Heroku Node.js Support.
https://devcenter.heroku.com/articles/deploying-nodejs

Why devDependencies is not installed

I developed a package for example: testlab, and its package.json is:
{
"devDependencies": {
"mocha": "^2.0.0"
},
"name": "#aab/testlab",
"version": "2.6.0",
"description": "example for npm",
"main": ".\\dest\\main.js",
"dependencies": {
"gulp": "^3.9.1",
"gulp-changed": "^1.3.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"test"
],
"author": "aab <aab#exmaple.com>",
"license": "ISC"
}
Say I included mocha in devDendencies, and then I created a local directory called e.g. c:\example and used
npm install #aab/testlab --only=dev
to get my package under c:\example, but when I looked at c:\example\node_modules, I did not find mocha package is installed. I also tried other command like
npm install #aab/testlab
still no luck. I used NodeJS v4.6.0 and npm 4.0.2. Although nodeJS seems a little old, could any one help me that?
I have seen this happen only when NODE_ENV is set to PRODUCTION. Something else might be setting it.

Is it possible to reference a property in package.json

Consider the following package.json:
{
"name": "expressapp",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"dev": "./node_modules/.bin/nodemon app.js"
},
"author": "me",
"license": "ISC",
"dependencies": {
"express": "^4.13.4",
"mongodb": "^2.1.7"
},
"devDependencies": {
"nodemon": "^1.9.1"
}
}
Now I want to rename my app.js to index.js. So I have to edit that name at least in two different places: main property and dev property of scripts. Is it possible to reference the value of main property inside package.json?
You can do it through environment variables
Under Linux
"scripts": {
"dev": "./node_modules/.bin/nodemon $npm_package_main"
},
Under Windows
"scripts": {
"dev": "./node_modules/.bin/nodemon %npm_package_main%"
},
JSON itself doesn't support variables.
It's up to the program consuming JSON that can decide whether to treat any particular pattern as a variable or to be replaced with some other text somehow.
While other answers have mentioned using the $ or %% notation for variables (that are OS-dependent), I think you can also solve your problem in the following way:
Instead of nodemon app.js you can just write nodemon .:
"main": "app.js",
"scripts": {
"dev": "nodemon ."
}
. will also automatically resolve to app.js
If you have a "main": "app.js" in package.json (in any folder, be it top level or sub folders) then any node process will identify the app.js file as the default one to load (either in require calls or executing via cli), just like it does index.js automatically.
Yes, you can reference to any field value from package.json when executing scripts.
But there is a difference, when you run script under windows, you should use %npm_package_field% and with unix based OS you should use $npm_package_field.
Where field is field name from package.json.
Under windows, you can use:
"dev": "./node_modules/.bin/nodemon %npm_package_main%"
Under unix:
"dev": "./node_modules/.bin/nodemon $npm_package_main"

Resources