| Prochaine révision | Révision précédente |
| prog:nodejs:npm [2020/05/18 17:39] – Création avec "package.json" et "Syntaxe des versions" root | prog:nodejs:npm [2025/11/17 09:36] (Version actuelle) – Déprécié root |
|---|
| ===package.json=== | <WRAP center round important 60%> |
| | L'utilisation de ''npm'' est globalement déprécié par les utilisateurs. Il est préférable d'utiliser plutôt ''yarn'' ou ''pnpm''. La syntaxe reste la même pour l'usage basique (99% des utilisateurs). |
| | </WRAP> |
| |
| * Syntaxe des versions | =====Configuration===== |
| | |
| | ====Proxy==== |
| | |
| | Exécuter : |
| | |
| | npm config set proxy http://xxx.yyy.zzz.aaa:80 |
| | |
| | =====Commandes===== |
| | |
| | ====install==== |
| | |
| | Installer dependencies et devDependencies : ''npm install'' |
| | |
| | Installer dependencies : ''npm install %%--%%production'' |
| | |
| | Installer devDependencies : ''npm install %%--%%dev'' |
| | |
| | =====Fichiers===== |
| | |
| | ====package.json==== |
| | |
| | ===Syntaxe des versions=== |
| |
| ^Version^Description^ | ^Version^Description^ |
| |''<version'' | | | |''<version'' | | |
| |''%%<=%%version'' | | | |''%%<=%%version'' | | |
| |''~version'' | “Approximately equivalent to version” See semver | | |''~version'' | ~1.2.3 autorise 1.2.3 jusqu'à <1.3.0 | |
| |''^version'' | “Compatible with version” See semver | | |''^version'' | %%^%%2.3.4 autorise 2.3.4 jusqu'à <3.0.0 | |
| |''1.2.x'' | 1.2.0, 1.2.1, etc., but not 1.3.0 | | |''1.2.x'' | 1.2.0, 1.2.1, etc., but not 1.3.0 | |
| |''%%http://...%%'' | See ‘URLs as Dependencies’ below | | |''%%http://...%%'' | See ‘URLs as Dependencies’ below | |
| |''*'' | Matches any version | | |''*'' | Matches any version | |
| |''%%""%%'' | (just an empty string) Same as ''*'' | | |''%%""%%'' | (just an empty string) Same as ''*'' | |
| |''version1 - version2'' | Same as ''>=version1 <=version2''. | | |''version1 - version2'' | Same as ''>=version1 %%<=%%version2''. | |
| |''range1 || range2'' | Passes if either range1 or range2 are satisfied. | | |''range1 || range2'' | Passes if either range1 or range2 are satisfied. | |
| |''git%%...%%'' | See ‘Git URLs as Dependencies’ below | | |''git%%...%%'' | See ‘Git URLs as Dependencies’ below | |
| [[https://docs.npmjs.com/files/package.json|Specifics of npm's package.json handling]] {{ :prog:nodejs:npm:npm-package.json_npm_documentation_2020-05-18_5_28_00_pm_.html |Archive le 18/05/2020}} | [[https://docs.npmjs.com/files/package.json|Specifics of npm's package.json handling]] {{ :prog:nodejs:npm:npm-package.json_npm_documentation_2020-05-18_5_28_00_pm_.html |Archive le 18/05/2020}} |
| |
| * Avoir la liste des versions d'un paquet | [[https://michaelsoolee.com/npm-package-tilde-caret/|What's the difference between a tilde (~) and a caret (^) in a npm package.json file?]] {{ :prog:nodejs:npm:what_s_the_difference_between_a_tilde_and_a_caret_in_a_npm_package.json_file_michael_lee_2021-08-17_05_35_38_.html |Archive du 13/07/2017 le 17/08/2021}} |
| | |
| | ===Avoir la liste des versions d'un paquet=== |
| |
| npm view paquet versions --json | npm view paquet versions --json |
| |
| | ===Mettre à jour les paquets dans package-lock.json=== |
| | |
| | Il parait que la commande ci-dessous fonctionne. Mais pas chez moi. |
| | |
| | <code bash> |
| | npm outdated |
| | npm update -dd |
| | npm install |
| | </code> |
| | |
| | ===Mettre à jour les paquets dans package.json=== |
| | |
| | Installer le paquet ''npm-check-updates'' et exécuter la mise à jour. |
| | |
| | Attention, cela force la dernière mise à jour sans vérifier la compatibilité entre les paquets. |
| | |
| | <code bash> |
| | npm i --location=global npm-check-updates |
| | npm-check-updates -u |
| | npm install |
| | </code> |
| | |
| | =====Erreurs===== |
| | |
| | * ''npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!'' |
| |
| | Lancer un ''npm install -g npm'' |