The project #superflycss/component-navbox has the following dependencies:
"devDependencies": {
"#superflycss/component-body": "^1.0.1",
"#superflycss/component-display": "^1.0.2",
"#superflycss/component-header": "^2.1.0",
"#superflycss/component-test": "^3.6.14",
"#superflycss/foundation": "^2.0.3",
"#superflycss/superflycss": "^1.0.0",
"#superflycss/utilities-colors": "^3.0.8",
"#superflycss/utilities-effects": "^2.1.0",
"#superflycss/utilities-fonts": "^3.3.7",
"#superflycss/utilities-format": "^1.1.1",
"#superflycss/utilities-layout": "^4.0.4",
"lite-server": "^2.4.0",
"npm-check-updates": "^2.15.0"
},
"dependencies": {
"#superflycss/variables-dimension": "^2.0.0",
"#superflycss/variables-layout": "^2.0.0"
}
So when doing:
git clone git#github.com:superflycss/component-navbox.git
cd component-navbox
npm i
I would expect only the root dependencies to show up in the node_modules folder.
However another dependency variables-colors also shows up in node_modules.
IIUC this should not happen or am I missing something?
One of the problems with this is that the variables-colors version being installed is outdated, however since utilities-colors also depends on this, it uses the older version rather then the newer, and that leads to linting errors, etc.
There was a mismatch between package-lock.json and package.json. I removed the lock file and also node_modules and did npm i and it refreshed with all the dependencies being correct.
Related
I'm trying to run old project on the team Drive, but I'm not sure what node version I will use. Is there a way for me to check it in the code or using the terminal?
Another questions:
In the READ ME File, it says here that it use Angular CLI version 6.0.3. -- so do I need to use this version?
Do I need to update the version of my dependency since this one is an old angular project? If yes, how? What command do I need to use?
Is it okay to delete the node_modules and package-lock.json if I use npm install?
This is my whole package.json
{
"name": "sample-tool",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#agm/core": "^1.0.0-beta.7",
"#angular/animations": "^8.2.0-next.1",
"#angular/common": "^8.2.0-next.1",
"#angular/compiler": "^8.2.0-next.1",
"#angular/core": "^8.1.1",
"#angular/fire": "^5.4.2",
"#angular/forms": "^8.2.0-next.1",
"#angular/platform-browser": "^8.2.0-next.1",
"#angular/platform-browser-dynamic": "^8.2.0-next.1",
"#angular/router": "^8.2.0-next.1",
"#ng-bootstrap/ng-bootstrap": "^4.2.1",
"#swimlane/ngx-charts": "^10.1.0",
"#swimlane/ngx-datatable": "^15.0.2",
"angular-calendar": "^0.25.2",
"angular-datatables": "^6.0.1",
"angular-file-uploader": "^5.0.2",
"angular-notifier": "^4.1.1",
"bootstrap": "^4.4.1",
"bootstrap-icons": "^1.0.0-alpha2",
"c3": "^0.4.23",
"chart.js": "^2.8.0",
"chartist": "^0.11.3",
"core-js": "^2.6.9",
"d3": "^4.8.0",
"datatables.net": "^1.10.19",
"datatables.net-dt": "^1.10.19",
"file-saver": "^2.0.2",
"firebase": "^7.9.3",
"jquery": "^3.4.1",
"lodash": "^4.17.14",
"ng-chartist": "^1.1.1",
"ng-multiselect-dropdown": "^0.2.3",
"ng2-charts": "^1.6.0",
"ng2-completer": "^2.0.8",
"ng2-dragula": "^2.1.1",
"ng2-search-filter": "^0.5.1",
"ng2-slim-loading-bar": "^4.0.0",
"ng2-smart-table": "1.3.5",
"ng2-validation": "^4.2.0",
"ngx-perfect-scrollbar": "6.1.0",
"ngx-quill": "^7.0.2",
"ngx-toastr": "^8.10.2",
"node-sass": "^4.12.0",
"pace-js": "^1.0.2",
"quill": "^1.3.6",
"rxjs": "^6.5.2",
"rxjs-compat": "^6.5.2",
"xlsx": "^0.15.5",
"zone.js": "~0.9.1"
},
"devDependencies": {
"#angular-devkit/build-angular": "^0.803.23",
"#angular/cli": "^8.1.1",
"#angular/compiler-cli": "^8.2.0-next.1",
"#angular/language-service": "^8.2.0-next.1",
"#types/c3": "^0.6.4",
"#types/chartist": "^0.9.46",
"#types/datatables.net": "^1.10.17",
"#types/jasmine": "^2.8.16",
"#types/jasminewd2": "^2.0.6",
"#types/jquery": "^3.3.30",
"#types/node": "~8.9.4",
"codelyzer": "^5.0.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.2.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^5.4.1",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~3.4.5"
}
}
The project is obviously Angular v8.
So I would say you should do the following steps:
1. Step - Install newest Angular CLI
Angular CLI will recognize if the project itself is using older version of Angular, so no need to limit yourself to the old version of the CLI.
2. Step - Install correct version of the Node.js
For Angular v8, you need Node v10.9.
Note: This Stack Overflow answer have compatibility table, so you can check it once you start upgrading your project.
3. Step - Install dependencies
Install all the dependencies with npm install.
Note: Don't delete package-lock.json and do npm install. package-lock.json keeps the dependency versions and if you delete it and do npm install, it can install newer versions, which can break you project.
4. Step - Run the project
Run the project with npm start.
5. Step (Optional) - Upgrade project to latest version
You can now gradually upgrade your app to newer versions. You can check Angular official guide for upgrading projects.
Note: It is recommended to upgrade only one version at a time. So you should first upgrade to v9, then to v10...
Note: When you upgrade Angular project, you should first upgrade all third-party dependencies to the next version. Otherwise, Angular will throw an error when upgrading, if it finds something incompatible.
Great answer by NeNaD. I just want to add this helpful article that I referred to when I was upgrading my old Angular project, https://www.angularjswiki.com/angular/update-angular-cli-version-ng-update-to-latest-6-7-versions/
Based on your questions:
I'm not sure what node version I will use. Is there a way for me to check it in the code or using the terminal?
You can make use of the node version command as
node -v
or
node --version
it says here that it use Angular CLI version 6.0.3. -- so do I need to use this version?
You could look into upgrade options but since its a old version and you are trying to run it. I would recommend to first use the same version as to see how its running and doesn't cause any abnormalities and then you could upgrade as others suggested
Do I need to update the version of my dependency since this one is an old angular project? If yes, how? What command do I need to use?
I would recommend you do not and so you refer below what is going on.
Version numbers in semantic versioning consist of 3 sets of numbers separated by a ., for example 1.2.3 which represent major.minor.patch respectively. The semantic version documentation explains each of these:
MAJOR version when you make incompatible API changes,
MINOR version when you add functionality in a backwards compatible manner, and
PATCH version when you make backwards compatible bug fixes.
In the package.json, for each dependency you will see a corresponding semver number. Sometimes this is prefixed with a carat ^ or tilde ~.
^1.2.3 — install the latest version of 1.X.X (don’t go past specified major, only a higher minor and patch number).
~1.2.3 — install the latest version of 1.2.X (don’t go past specified major or minor, only a higher patch number).
You can use range operators (e.g. >=) if you need more fine tuned control of the version range.
Is it okay to delete the node_modules and package-lock.json if I use npm install?
You can remove the node_modules as it will be re-created when you re-install using the package.json but keep in mind that if there have been changes made to the node_modules packages then they might be overwritten but this generally doesn't happen but its good to know.
Don't delete your package-lock.json make a copy of it somewhere. Also, deleting the file can affect your version control.
why?
Imagine the project has a dependency, example-package at version ^1.0.0. This is the latest available version at the time of first install and is added to the lock file as 1.0.0. A month later, a new release of example-package comes out 1.1.0. Let’s pretend a new developer joins your team and clones the project repository, and installs the project.
The version in the package.json is ^1.0.0 (meaning the latest 1.X.X), so you would think that the 1.1.0 would be installed on the new developer’s machine, but this is not the case. When the dependency was first added to the project, 1.1.0 did not exist, so the version listed in the lock file is 1.0.0. Therefore 1.0.0 will always be installed, despite there being a newer available version that meets the semantic version specification in the package.json.
If you do not commit the lock file to your repository, or delete the lock file and reinstall your node modules, then version 1.1.0 of example-package will be installed, since it will be treated as if this is the first time installing. New bugs could have been introduced into 1.1.0, or the maybe the package dependencies changed and are incompatible with other dependencies in your project.
This is how deleting the lock file can unintentionally cause dependencies to be upgraded which can break your application.
I have a package.json
"dependencies": {
"#babel/core": "7.2.2",
"#babel/preset-env": "7.3.1",
"#babel/register": "7.0.0",
"babel-loader": "8.0.5",
"browser-sync": "^2.26.0",
"#hot-loader/react-dom": "^16.8.6",
"react": "^16.10.1",
"react-dom": "^16.10.1",
"react-hot-loader": "^4.12.13",
"webpack": "^4.41.0",
"glob": "^7.1.6",
"args": "^5.0.1",
"webpack-dev-middleware": "^3.7.2",
"webpack-hot-middleware": "^2.25.0"
},
I have two build processes:
Build A - standard app.
git clone <myrepo.git>
npm install
npm run build-app
deploy
Build B - static files
git clone <myrepo.git>
npm install glob args // I want to read this from package.json
npm run build-static
deploy-static
What I would like is to group dependencies into two groups.
The reason is installing all the dependencies takes about ~2mins. For second build task, I only need 2-3 packages which takes less than 10 seconds. Currently, I have npm install glob args hardcoded in my build program. I want to read it from the same package.json.
I cannot use dependencies vs dependencies because I have some dependencies used just for development and use the flag npm install --production to install only the required dependencies (without devDependencies).
You can surely group them; there are two types of dependencies, one's dev and the other one is production. Here's a reference: https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file
If you want to create more than two, check this package out: https://www.npmjs.com/package/group-dependencies
I would like to convert my existing react native app to typescript.
The documentation says to uninstall existing dependencies and replace them with something like this:
yarn add --dev #types/jest #types/react #types/react-native #types/react-test-renderer
Do I need to do this with every dependency? What if some dependencies don't have #types/ ?
Here is my package.json:
{
"name": "reactnative",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"axios": "^0.18.0",
"expo": "^28.0.0",
"faker": "^4.1.0",
"formik": "^0.11.11",
"immutability-helper": "^2.7.1",
"lodash": "^4.17.10",
"native-base": "^2.7.1",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-actionsheet": "^2.4.2",
"react-native-autogrow-textinput": "^5.1.1",
"react-native-firebase": "^4.2.0",
"react-native-keyboard-input": "^5.2.3",
"react-native-keychain": "^3.0.0-rc.3",
"react-native-material-color": "^1.0.15",
"react-native-parsed-text": "0.0.20",
"react-native-section-list-get-item-layout": "^2.2.3",
"react-native-ui-kitten": "^3.0.1",
"react-native-vector-icons": "^4.6.0",
"react-navigation": "^2.5.5",
"react-redux-firebase": "^2.1.6",
"recompose": "^0.27.1",
"redux-logger": "^3.0.6",
"redux-promise-middleware": "^5.1.1",
"redux-thunk": "^2.3.0",
"yup": "^0.25.1"
},
The documentation says to uninstall existing dependencies and replace them
Actually you have to install both the package, such as react and the related types as #types/react. If react is already installed, you don't have to uninstall and reinstall.
Do I need to do this with every dependency?
As long as you want types for it.
What if some dependencies don't have #types/ ?
Then you either type it on your own, or you type it as any and you don't have the typesafety of Typescript anymore.
No, packages that start with #types/ are TypeScript definitions. They should be installed in addition to the actual packages if these don't already ship with TS definitions (many large/popular libraries do). Your editor and the TypeScript compiler will use the definitions to perform type checking.
#types typings exist for all popular libraries. Some libraries include typings (.d.ts files), no typings are needed for them, the example is axios.
For libraries that don't have typings, a developer can provide own type declarations or use untyped imports, e.g. with require. The example is open issue for react-native-actionsheet.
The documentation says to uninstall existing dependencies
The documentation shouldn't say anything like that. Existing dependencies shouldn't be uninstalled. Only respective #type dependencies should be added.
This question already exists:
How to handle script dependencies in angular 2 module published to npm
Closed 5 years ago.
I have published an angular 2 library to npm recently.I have listed all the dependency scripts in the libraries package.json file. when I run npm install my-library all the dependency scripts are not installed.So, my question is how to install the dependency scripts while installing the library.
(This answer is valid for npm5+) In package.json you can specify 3 types of dependencies:
peerDependencies - they are not automatically downloaded in any case ("good to have")
devDependencies - which are downloaded when running npm install in the project itself, packages listed here are needed for development purposes only
dependencies - which are downloaded on every npm install (also when adding your package to someone's project, "must-to-have")
Example:
{
"peerDependencies": {
"#angular/core": ">=2.3.0",
},
"devDependencies": {
"#angular/compiler": "~4.0.0",
"#angular/compiler-cli": "~4.0.0",
"#angular/core": "~4.0.0",
"#angular/platform-server": "~4.0.0",
"#types/node": "^7.0.39",
"core-js": "^2.4.1",
"es6-shim": "^0.35.3",
"rimraf": "^2.5.4",
"rxjs": "^5.4.2",
"tslint": "^4.5.0",
"typescript": "^2.6.1",
"zone.js": "^0.8.16"
},
"dependencies": {
"ngx-store": "^1.2.2"
}
}
With recent update of React to 0.15 where they fixed excessive generation of tags, I decided to update the project.
The problem is that when I did npm update, it updated to 0.14.8 and that's it.
npm outdated shows:
Package Current Wanted Latest Location
history 1.17.0 1.17.0 2.1.0 history
react 0.14.8 0.14.8 15.0.1 react
react-dom 0.14.8 0.14.8 15.0.1 react-dom
react-router 1.0.3 1.0.3 2.3.0 react-router
react-select 0.9.1 0.9.1 1.0.0-beta12 react-select
My package.json looks like:
"dependencies": {
"extract-text-webpack-plugin": "^1.0.1",
"history": "^1.17.0",
"moment": "^2.11.0",
"node-sass": "^3.4.2",
"react": "^0.14.5",
"react-dom": "^0.14.5",
"react-recaptcha": "^2.0.1",
"react-redux": "^4.0.6",
"react-router": "^1.0.3",
"react-select": "^0.9.1",
"redux": "^3.0.5",
"sass-loader": "^3.1.2"
}
I tried to change versions to 0.15.0, but then I get an error:
npm ERR! notarget No compatible version found: react-dom#'>=0.15.0 <0.16.0'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["0.1.0","0.14.0-beta1","0.14.0-beta2","0.14.0-beta3","0.14.0-rc1","0.14.0","0.14.1","0.14.2","0.14.3","0.14.4","0.14.5","0.14.6","0.15.0-alpha.1","0.14.7","15.0.0-rc.1","15.0.0-rc.2","0.14.8","15.0.0","15.0.1"]
I am still new with npm, so sorry if the question is stupid.
What is the right way to update all that packages?
In this case npm update works as expected. Latest version that satisfies caret dependency "^0.14.5" is 0.14.8.
React switched to using major versions after v0.14.8 (see React blog).
Latest stable version now is 15.x not 0.15.x, so you should update your package.json file:
"dependencies": {
...
"react": "^15.0.1",
"react-dom": "^15.0.1",
...
}