I'm getting this error on build using tsc - node.js

I'm getting this error on the build using tsc
Can someone check this, please?
node_modules/#types/node/index.d.ts:75:11 - error TS2300: Duplicate identifier 'IteratorResult'.
75 interface IteratorResult<T> { }
I'm using latest typescript and #types/node
My package json configuration
"dependencies": {
"bcrypt": "^3.0.2",
"bluebird": "^3.5.1",
"body-parser": "^1.18.2",
"dotenv": "^6.2.0",
"express": "^4.16.2",
"express-statsd": "^0.3.0",
"express-validator": "^5.3.0",
"hashids": "^1.2.2",
"jsonwebtoken": "^8.4.0",
"mailgun-js": "^0.22.0",
"mysql2": "^1.5.1",
"nyc": "^13.1.0",
"reflect-metadata": "^0.1.10",
"sequelize": "^5.21.7",
"sequelize-typescript": "^1.1.0",
"strong-error-handler": "^2.3.0",
"supertest": "^3.3.0",
"uuid": "^3.3.2"
},
"devDependencies": {
"#types/express": "^4.0.39",
"#types/mocha": "2.2.41",
"#types/node": "12.12.31",
"mocha": "^5.2.0",
"ts-node": "^8.4.1",
"tslint": "^5.8.0",
"typescript": "^3.8.3"
}
someone can help me, please?
Any update to do?

I would suggest you to reinstall your packages. This should solve your problem.
sudo rm -rf node_modules/ package-lock.json
sudo npm cache clean --force
sudo npm install -D #types/node
sudo npm i --unsafe-perm
Ps: You may get some type errors after all these fresh installs. This is something you will have to fix by declaring or correcting or installing "#types/". You have reinstalled your modules and some type errors appeared.Find the the code where the types are not compatible and fix it. This way you will understand reading typescript errors and fixing types. And your code will be type safe, whole point of using Typescript.

Did you try npm install package.json (if you are not using visual code terminal you might need to add the correct path to your file!)

Related

Cannot find module '#nestjs/core' or its corresponding type declarations

Couple of weeks ago I installed NestJS globally on my computer.
Now I'm coming back to that, to start learning.
So I created new project with comand:
nest new ./
It generated all the files, but when I try to run this application with command:
nest start
I expected this template project to start but there are errors with importing paths?
Is this due to version of my installed Nest or something?
Errors on the screen:
Version of my Nest:
7.5.6
Package.json:
"dependencies": {
"#nestjs/common": "^7.6.13",
"#nestjs/core": "^7.6.13",
"#nestjs/platform-express": "^7.6.13",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.6"
},
"devDependencies": {
"#nestjs/cli": "^7.5.6",
"#nestjs/schematics": "^7.2.7",
"#nestjs/testing": "^7.6.13",
"#types/express": "^4.17.11",
"#types/jest": "^26.0.20",
"#types/node": "^14.14.31",
"#types/supertest": "^2.0.10",
"#typescript-eslint/eslint-plugin": "^4.15.2",
"#typescript-eslint/parser": "^4.15.2",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"supertest": "^6.1.3",
"ts-jest": "^26.5.2",
"ts-loader": "^8.0.17",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.1.5"
},
I had the same issue. The following two commands fixed it:
npm install #nestjs/common
npm install #nestjs/core
These commands make sure you are using the lastest versions of those packages.
Run
npm i --save #nestjs/config
Reference: https://docs.nestjs.com/techniques/configuration
Run this command in terminal "npm install --save #nestjs/config"
I've stuck with this problem when I built a nodejs application (like, express, nestjs, etc.)
So when you build a nodejs app, the build(dist) folder just contains your code, not node_modules.
You can copy node modules to a build folder, like:
cp package.json build/package.json && cd build && npm install --only=production
Or try other solutions

NPM : Error: Cannot find module 'balanced-match'

I just updated the node and npm using nvm. When I start the node server I am getting this error. I tried with different solutions. This type of questions already existed in stack overflow but none of these worked for me. So I tried with these things but no use.
1.Removed node modules and install node modules with npm install.
2.Updated babel-cli version.
3.downgraded node and nvm.
4.npm i balanced-match.
5.npm i -g balanced-match.
6.npm i balanced-match --save.
I am adding my package.json
{
"name": "******",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon express-server.js --exec babel-node",
"build": "babel ./ -d dist",
"serve": "node dist/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel": "^6.23.0",
"bluebird": "^3.5.1",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"ejs": "^2.6.1",
"express": "^4.16.3",
"express-es6-template-engine": "^2.0.3",
"express-session": "^1.15.6",
"handlebars": "^4.0.11",
"helmet": "^3.13.0",
"html": "^1.0.0",
"instamojo-nodejs": "0.0.5",
"jsonwebtoken": "^8.2.2",
"lodash": "^4.17.10",
"moment": "^2.22.2",
"mongoose": "^5.1.3",
"mongoose-unique-validator": "^2.0.1",
"multer": "^1.3.0",
"mysql": "^2.15.0",
"node-fetch": "^2.1.2",
"node-schedule": "^1.3.0",
"node-xlsx": "^0.12.1",
"nodemailer": "^4.6.8",
"passport": "^0.4.0",
"passport-google-oauth20": "^1.0.0",
"passport-local": "^1.0.0",
"request": "^2.88.0",
"request-ip": "^2.0.2",
"sanitize-html": "^1.18.2",
"utf8": "^3.0.0",
"validator": "^10.2.0",
"xlsx2json": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"nodemon": "^1.17.5"
}
}
In console it showing like this.
console error
I wasted 12 hours time to solve this problem only.
I solved this problem by installing the balanced-match with npm install balanced-match in root folder. I don't know why it is taking root folder node modules. In console error it is clearly given path but I have not aware of it. If anyone explain why it is taking root node modules that would be helpful to me.
I did not see any node packages as balanced-match. Hence, it is giving the error. You can also manually add package in package.json and run npm install.
If you ran this command: npm i balanced-match --save there would be an entry for it in your package.json file. Does your app require this module for production or is it a development tool? That will determine which flag you should pass to the install command. From the docs:
-P, --save-prod: Package will appear in your dependencies. This is the default unless -D or -O are present.
-D, --save-dev: Package will appear in your devDependencies.
-O, --save-optional: Package will appear in your optionalDependencies.
--no-save: Prevents saving to dependencies.
When using any of the above options to save dependencies to your
package.json, there are two additional, optional flags:
-E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm’s default semver range operator.
-B, --save-bundle: Saved dependencies will also be added to your bundleDependencies list.
The previous answer does have the most likely fix for your problem. You can either run the install command again with the correct flag for your use case (which will install it and update your package.json), or you can add it manually and run npm install again.
When you install, are there any errors at all? If not, it should work. You can check for installed packages using npm ls (passing optional tags like '-g' will show you all globally installed modules, and you can modify the output by also passing a depth tag like such: --depth=0.

Nodes_modules packages duplicated

Im using npm to install several packages for my application.
So I got one node_modules that contains all the packages. However several packages contains itself some node_modules and these node_modules contains other packages...
My problem is that the packages may be duplicated in the several node_modules, so I m searching a solution to remove this duplications.
This what I have tried :
npm dedupe : it doesnt resolve my problem and the duplication still present
flatten-packages : this resolved the duplciations but my app stopped to work because it says that the packages are not finding the dependencies it needs....
I m using npm 6.1.0
here are an example of my dependencies and devDependencies
"dependencies": {
"axios": "^0.17.0",
"cpx": "^1.5.0",
"lodash": "^4.17.5",
"node-sass-chokidar": "0.0.3",
"npm-run-all": "4.1.1",
"object-mapper": "^5.0.0",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-intl": "^2.4.0",
"react-number-format": "^3.3.1",
"react-promise": "^2.0.1",
"react-redux": "^5.0.7",
"redux": "^3.7.2",
},
"devDependencies": {
"eslint": "^4.18.2",
"eslint-plugin-react": "^7.7.0",
"jest": "^22.4.4"
}
Any ideas ?
There can be different versions of same package.
if dependency 'A' needs dependency 'B' with version specified as '^1.0.0'
and another dependency 'C' needs dependency 'B' but with version specified as '^2.0.0'
Package managers can put a less used version inside node_modules of another package.
It is by design.

Npm is ignoring dependencies

I decided to move my project into different folder. I didn't copy the node-modules folder.
When I run npm install, it said nothing and installed nothing. Obviously it looked into devDependencies section instead of Dependencies that I used before.
How can I make npm install all from Dependencies?
My package.json:
{
"name": "zzz",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"ejs": "~2.5.7",
"express": "~4.15.5",
"express-session": "^1.15.6",
"grunt": "^1.0.1",
"grunt-contrib-less": "^1.4.1",
"grunt-exec": "^3.0.0",
"grunt-link-html": "^0.1.2",
"moment": "^2.20.1",
"mongoose": "^5.0.0-rc1",
"morgan": "~1.9.0",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"serve-favicon": "~2.4.5"
}
}
If I try to install package individually it creates and updates devDependencies section, not dependencies as expected.
Solution found. It turned out that NPM stops working as expected if you have spaces in the "name" in package.json. As soon as I removed them NPM started working. It was so confusing!
There is a typo in your json in the form of a blank space near "serve-favicon": "~2.4.5". Better use an IDE like VSCODE and an extension like beautify to avoid unnecessary errors.Also its asking for a dependency "grunt#~0.4.0" . So install it and do npm install.

node npm install to central location

I was wondering if it is possible to do a single installation of node packages that can then be accessed by different development applications. For example, whenever I'm working on a react app, I do npm install to get all node packages the app needs. However, it seems that this gets a lot of unneeded extras. Is there a way
to just get what my app needs as specified in the package file or
get everything into the node modules folder in the installation folder and access the packages from there without having to reinstall them locally in every app folder.
I'm adding the following since my question is not being answered:
Let's say I have the following package.json. If I navigate to my app folder where this package.json file is located and I do npm install, what gets installed and where? My assumption is that only the packages listed in devDependencies and in dependencies will be installed and that it will be installed locally since I did not specify global. So why do I see hundreds of other packages (packages not in the list below) when I go into my node_modules folder in my app?
what I would like is to install only the packages listed below and to make them global so that if I go into another app directory I do not have to reinstall these.
{
"devDependencies": {
"babel-eslint": "7.1.1",
"babel-jest": "18.0.0",
"concurrently": "3.1.0",
"enzyme": "2.7.1",
"eslint": "3.12.1",
"eslint-config-defaults": "9.0.0",
"eslint-plugin-react": "6.7.1",
"jest": "18.1.0",
"json-server": "0.9.4",
"react-addons-test-utils": "15.4.2",
"react-test-renderer": "15.4.2",
"rimraf": "2.5.4",
"sass-lint": "1.10.2",
"tslint": "4.3.1",
"webpack-dev-server": "2.6.1"
},
"dependencies": {
"bootstrap": "4.0.0-alpha.6",
"bootstrap-loader": "2.0.0-beta.20",
"copy-webpack-plugin": "4.0.1",
"css-loader": "0.26.1",
"empty": "0.10.1",
"extract-text-webpack-plugin": "2.0.0-rc.3",
"file-loader": "0.10.0",
"html-loader": "0.4.3",
"html-webpack-plugin": "2.26.0",
"key-mirror": "1.0.1",
"lodash": "4.16.2",
"node-sass": "4.5.0",
"null-loader": "0.1.1",
"postcss": "5.2.9",
"postcss-import": "9.1.0",
"postcss-loader": "1.2.1",
"raw-loader": "0.5.1",
"react": "15.4.2",
"react-addons-css-transition-group": "15.4.2",
"react-dom": "15.4.2",
"react-redux": "5.0.2",
"react-router": "3.0.0",
"react-router-redux": "4.0.7",
"redux": "3.6.0",
"redux-thunk": "2.1.0",
"resolve-url-loader": "1.6.1",
"sass-loader": "5.0.1",
"style-loader": "0.13.1",
"ts-loader": "1.3.3",
"typescript": "2.1.4",
"url-loader": "0.5.7",
"webpack": "2.2.1",
"whatwg-fetch": "2.0.3"
},
}
This is exactly what global packages are for. npm i -g <package> also i recommend using nvm to manage your different node versions. This way you can have different global packages depending on version. You can even set aliases for multiple installs.
You can globally install nodeJs and then do npm install for the packages you need and save it in package.json. This way you would know which packages to install next time and just do npm install.

Resources