8
0

version.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module utils/version
  7. */
  8. /* globals window, global */
  9. import log from './log';
  10. import { version } from 'ckeditor5/package.json';
  11. const windowOrGlobal = typeof window === 'object' ? window : global;
  12. if ( windowOrGlobal.CKEDITOR_VERSION ) {
  13. /**
  14. * This error is thrown when the `CKEDITOR_VERSION` global is being set more than once. This happens when in
  15. * two scenarios described above.
  16. *
  17. * # Some packages were duplicated
  18. *
  19. * CKEditor 5 was built from source packages which were duplicated during installation via npm.
  20. * Normally, npm deduplicates all packages so e.g. `@ckeditor/ckeditor5-core` is installed only once in `node_modules/`.
  21. * However, subsequent `npm install` calls or conflicting version dependencies may cause npm to install some packages
  22. * more than once. Furthermore, [npm in version 5+](https://github.com/npm/npm/issues/16991)
  23. * is also known for randomly failing to deduplicate packages.
  24. *
  25. * We recommend checking if any of the below steps helps:
  26. *
  27. * * `rm -rf node_modules && npm install` to make sure you have a clean `node_modules/` – this step
  28. * is known to help in majority of cases,
  29. * * check whether all CKEditor 5 packages are up to date and reinstall them
  30. * if you changed anything (`rm -rf node_modules && npm install`),
  31. * * downgrade npm to version 4 if you use a newer version.
  32. *
  33. * If all packages are correct and compatible with each other the above steps are known to help. If not, you may
  34. * try to check with `npm ls` how many times `@ckeditor/ckeditor5-core` is installed. If more than once, verify
  35. * which package causes that.
  36. *
  37. * # Two+ builds are loaded
  38. *
  39. * If you use CKEditor 5 builds, you might have loaded two (or more) `ckeditor.js` files in one web page
  40. * – check your web page for duplicated `<script>` elements or make sure your page builder/bundler includes CKEditor only once.
  41. *
  42. * @error ckeditor-version-collision
  43. * @param {String} collidingVersion The version of the build which has already been (incorrectly) loaded.
  44. * @param {String} version The version of the build which is supposed to be loaded.
  45. */
  46. log.error( 'ckeditor-version-collision: The global CKEDITOR_VERSION constant has already been set.', {
  47. collidingVersion: windowOrGlobal.CKEDITOR_VERSION,
  48. version
  49. } );
  50. } else {
  51. windowOrGlobal.CKEDITOR_VERSION = version;
  52. }