angular2 error in lodash js - node.js

I have tried to use lodash for datatable. Here is what I have tried:
npm install lodash - gave cannot find package error
searched issue and then tried npm install --save #types/lodash
this produced following output:
+-- UNMET DEPENDENCY #angular/common#~2.1.0
+-- UNMET PEER DEPENDENCY #angular/compiler#2.4.6 invalid
+-- UNMET DEPENDENCY #angular/core#~2.1.0
`-- #types/lodash#4.14.52
which I dont understand, since my package.json has following:
"#angular/common": "~2.1.0",
"#angular/compiler": "~2.1.0",
"#angular/core": "~2.1.0",
after this, IDE can find package, but when I run npm start/ng serve I get multiple errors
ERROR in [default] path\node_modules\#types\lodash\index.d.ts:192
81:20
Cannot find namespace '_'.
ERROR in [default] path\node_modules\#types\lodash\index.d.ts:190
21:57
Cannot find name 'Many'.
ERROR in [default] path\node_modules\#types\lodash\index.d.ts:194
41:0
Declaration or statement expected.
and first two errors repeat multiple times each, but with different number (i guess line)
What should i do, to solve this issue?

This problem occurs when you are installing a old module(as written in your package.json) but it is not available on git due to update in their version.
for solving this issue
1.Need to install the project’s local dependencies (that’s where it’s looking for lodash). To do that,
2.cd into the project directory and run npm install.
3.You can also try npm i --save lodash
If the package.json file exists, and if it contains the lodash dependency you could try to remove the node_modules folder and run following command:
$ npm cache clean
$ npm install
The first command will clean the npm cache. (just to be sure) The second command will install all (missing) dependencies of the project.

So what worked for me, was to get package.json file from another (working project) and run npm install. I still have no idea why mine didn't work, but that is what solved the issue.

Related

Unable to fix npm vulnerabilities

I am getting 6 vulnerabilities after running npm audit report:
I tried a solution and overridden the vulnerable versions of a particular package with their latest versions in package.json file like this:
"overrides": {
"nth-check": "2.1.1",
"#svgr/webpack": "6.5.1",
"#svgr/plugin-svgo": "6.5.1",
"svgo": "3.0.1",
"css-select": "5.1.0"
}
Then I updated the npm packages with npm update. But it did not change the result.
Tried another solution by making a resolution object in package.json and specified specific versions of a particular package, and ran it using npx i npm-force-resolutions but it gives this error:
npm ERR! could not determine executable to run.
But I am still unable to fix the npm vulnerabilities. Please help!
You should delete both node_modules and package-lock.json before launching npm install again; this will require more time to install all dependencies, but this will override all the version that are currently installed (it will bring also minor updates in dependencies).
Also, for this vulnerability, you only need to override nth-check. You can see the changes by executing npm list nth-check with and without the override (remember to delete both node_modules and package-lock.json).

Json dependencies NPM update- How fix vulnerabilities manually

I have lost 1 day in order to try to fix manually fews high vulnerabilities.
It was a waste of time.
I've read many post, blog and suggestion but I was unable to fix the problem.
Basically /css-what require an update to version 5.0.1 and the npm audit is telling that
│ Dependency of │ gulp-imagemin [dev]
│ Path │ gulp-imagemin > imagemin-svgo > svgo > css-select >
| css-what
I've run (on gulp-imagemin) the command npm update, then navigate to the next folder (imagemin-svgo) and again npm update etc etc. When I arrive to the css-what root, I run again npm update but it doesn't do anything;
Then I modified my package.json according
"resolutions": {
"trim-newlines": "^4.0.1",
"css-what": "^5.0.1",
"scripts": {
"preinstall": "npx npm-force-resolutions"
}
}
I went back to the main root to run npm i but it doesn't amended all branches;
Besides when I run npm ls css-what or npm ls trim-newlines I can see that the new version has been installed on the node_modules but older version still unchanged on the tree
root/tree
I was following https://hackernoon.com/how-fix-security-vulnerabilities-in-npm-dependencies-in-3-minutes-rq9g3y7u post but it doesn't worked for some reason, most probably my inexperience.
Thanks for your help
To fix vulnerability you can try :
npm audit -fix
To update you can also use npm-check-updates
npm update css-what worked for me

npm start not working due to webpack issue

I had installed expo globally to learn react-native seeing a tutorial.
Now when I'm trying to make a new react app and run npm start I'm getting the following message.
yarn start
yarn run v1.22.4
$ react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"webpack": "4.42.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:
/home/nikunj/node_modules/webpack (version: 4.43.0)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
6. Check if /home/nikunj/node_modules/webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I tried several approaches to solve the problem.
Firstly i followed the first 4 steps in the error message but they did'nt work out as when i did
npm ls webpack
it returned
/home/nikunj
└─┬ expo-cli#3.24.2
└─┬ #expo/xdl#57.9.31
├─┬ #expo/webpack-config#0.12.25
│ └── webpack#4.43.0 deduped
└── webpack#4.43.0
Then I uninstalled expo-cli globally using
yarn global remove expo-cli
but even if i do that it is still giving me the same tree for npm ls webpack.
I also tried doing npm rm home/nikunj/expo-cli#3.24.2 but that is not solving the problem as still i get the same tree on npm ls webpack

how to install only package.json dependencies with their own versions by using npm install or yarn

I work on a new project, but I can't install packages correctly. I used npm install, yarn, npm install --only=dev, but there aren't enough. I also try like that deleting node_modules and package-lock.json. The state was the same.
We use in the project babel's 6.x version. Babel has a update, 7.x, I think I get the error because of version differences when I run npm install, npm install --only=dev, yarn.
npm WARN deprecated babel-preset-es2015#6.24.1: � Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN babel-loader#8.0.4 requires a peer of #babel/core#^7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN babel-loader#8.0.4 requires a peer of webpack#>=2 but none is installed. You must install peer dependencies yourself.
I use WebStorm. Before that, I tried to get package for another project with npm install. "Npm" is not successful. WebStorm advice me using Yarn, and I used Yarn. It was worked.
What should I do in the state?
After npm install, when I run parcel index.html, I get the console error
"Uncaught TypeError: window.fooes is not a constructor", Uncaught ReferenceError: regeneratorRuntime is not defined.
I know that the code doesn't have a problem, because project work on the team's computer correctly.
The first and most important:
Never use npm and yarn at the same time. Choose one of them and use that only because they are both using lock files based on the installed packages.
Which one to use:
npm and yarn are both using the NPM software registry database. So in the end the final result when installing packages are the same, but yarn does the job much-much faster. Yarn was developed by Facebook because the slowness of npm. So I prefer yarn, I'm not using npm commands anymore.
To your problem:
Delete the package-lock.json and yarn.lock lock files in your project root directory.
Also delete the whole node_modules directory.
Now you have only your package.json file. Make a backup of this file!
Open the original package.json and I suggest you to first delete all entries from it
related to Babel and save it.
Now run the yarn command (without params) in the project root (where your package.json file is). This should install all your packages again.
Then install the latest packages of Babel using these commands:
yarn add -D #babel/core
yarn add -D #babel/preset-env
yarn add -D babel-loader
You may need other packages from Babel. Have a look on your backed up package.json and search for the latest versions in the npm registry or Babel's plugins documentation page for the remaining plugins (if any).

EINTEGRITY: npm 5.0 integrity check and modernizr.com dependency

I've encountered this error when installing deps of my package:
$ npm i
npm ERR! code EINTEGRITY
npm ERR! sha1-tU7jWojzuU8MIY2VLAx+BwluNo0= integrity checksum failed when using sha1: wanted sha1-tU7jWojzuU8MIY2VLAx+BwluNo0= but got sha1-oXYP0kzpbhku0KU+phy353lbBhQ=. (26624 bytes)
npm ERR! A complete log of this run can be found in:
npm ERR! /home/tlenex/.npm/_logs/2017-06-22T10_18_19_773Z-debug.log
the problem is with my Modernizr dependency:
"dependencies": {
"Modernizr": "https://modernizr.com/download?setclasses-flash"
}
is there any way to solve this or ignore this integrity check?
Currently I have to run
npm i https://modernizr.com/download?setclasses-flash
again to get things working, which overrides the "integrity" field for "Modernizr" in my package-lock.json.
This may happen every time there is a change in Modernizr package fetched from this link and my package dependencies need to be reinstalled (for example, each time on CI build)
If there is no other way of solving this? I hope I wont have to place package-lock.json in my .gitignore file :(
More data about my enviroment:
$ npm -v
5.0.3
$ node -v
v6.11.0
Edit package-lock.json , find the one you want to skip in this case the one that its failing
sha1-tU7jWojzuU8MIY2VLAx+BwluNo0
and remove the integrity parameter from it i.e
},
"range-parser": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
"integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=",
"dev": true
},
to...
},
"range-parser": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
"dev": true
},
after that run npm install, will check the rest, skip this integrity
The point of the integrity field is to alert you when something has changed, so if you do not want it to exist, you can disable package-lock.json files in your npmrc. Just set package-lock=false
Note: I am the developer of Modernizr, and spoke with the npm-cli team about this issue. The root cause appears to be the change of the SHA type between npm5 and earlier versions. Nuking the node_modules folder will fix it
Find all outdated packages and update theme:
npm outdated -g
sudo npm i -g outDatedPKG
Upgrade npm to lateste version with:
sudo npm i -g npm
Delete package-lock.json file.
Delete _cacache directory in ~/.npm:
npm cache verify
4.1. Every time i get that error, do steps 2 & 3.
If you still get the error, clear npm's cache:
npm cache clean --force
I had this same error and I solved it by :
Deleting package-lock.json
Running "npm install"
I finally resolved this issue.
Our team moved away from URL dependency without SEMVER notation, in this case https://modernizr.com/download?setclasses-flash and used modernizr-loader with webpack. There are also equivalents for gulp and grunt tools available on npm, pick and use one you like the most.
After using them, we finally get rid of returning EINTEGRITY npm error without nuking package-lock.json or node_modules.
Just do two things for the solution
first :
npm cache clean --force
second :
npm i -g npm
and than install what u want
$ rm -rf package-lock.json node_modules
$ npm install --cache /tmp/empty-npm-cache
If this fixes it, clear your global npm cache to fix the corruption.

Resources