npm ci выполняется локально, но не работает на gitlab

npm ci выполняется локально, но не работает на gitlab

При очередной сборке проекта (сборке Docker образа) джоба в гитлабе повалилась с ошибками:

#14 [build 8/10] RUN npm install
93#14 1.999 npm ERR! code ERESOLVE
94#14 2.002 npm ERR! ERESOLVE could not resolve
95#14 2.002 npm ERR!
96#14 2.002 npm ERR! While resolving: vite-plugin-vue2@1.9.3
97#14 2.002 npm ERR! Found: vite@4.4.11
98#14 2.002 npm ERR! node_modules/vite
99#14 2.003 npm ERR! dev vite@"^4.0.0" from the root project
100#14 2.003 npm ERR!
101#14 2.003 npm ERR! Could not resolve dependency:
102#14 2.003 npm ERR! peer vite@"^2.0.0-beta.23" from vite-plugin-vue2@1.9.3
103#14 2.003 npm ERR! node_modules/vite-plugin-vue2
104#14 2.003 npm ERR! dev vite-plugin-vue2@"^1.8.1" from the root project
105#14 2.003 npm ERR!
106#14 2.003 npm ERR! Conflicting peer dependency: vite@2.9.16
107#14 2.003 npm ERR! node_modules/vite
108#14 2.004 npm ERR! peer vite@"^2.0.0-beta.23" from vite-plugin-vue2@1.9.3
109#14 2.004 npm ERR! node_modules/vite-plugin-vue2
110#14 2.004 npm ERR! dev vite-plugin-vue2@"^1.8.1" from the root project
111#14 2.004 npm ERR!
112#14 2.004 npm ERR! Fix the upstream dependency conflict, or retry
113#14 2.004 npm ERR! this command with --force or --legacy-peer-deps
114#14 2.004 npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Я нашёл аналогичную проблему — https://stackoverflow.com/questions/71737553/npm-ci-passing-locally-but-failed-on-gitlab. Ситуация была 1 в 1: локально у разработчиков всё собирается, а на GitLab ошибки.

Спойлер: решение

npm ci --legacy-peer-deps

помогает.

Но я решил разобраться в вопросе немного поглубже, чтобы понимать что я сделал и что происходит. Есть вариант выполнить

npm ci --force

Вот тут о разнице выполнения этих команд на практике — https://stackoverflow.com/questions/66020820/npm-when-to-use-force-and-legacy-peer-deps/66035709#66035709. Файл package-lock.json наполняется разным содержимым.

В некоторых источниках при подобных проблемах предлагают выполнить:

Remove package-lock.json from your project
Remove node_modules folder 
Run npm install

Но это не тот случай.  Ключевое слово в ошибке — peer dependency. Приведу цитатой описание:

Peer dependencies

Automatically installing peer dependencies is an exciting new feature introduced in npm 7. In previous versions of npm (4-6), peer dependencies conflicts presented a warning that versions were not compatible, but would still install dependencies without an error. npm 7 will block installations if an upstream dependency conflict is present that cannot be automatically resolved.

You have the option to retry with --force to bypass the conflict or --legacy-peer-deps command to ignore peer dependencies entirely (this behavior is similar to versions 4-6).

Since many packages in the ecosystem have come to rely on loose peer dependencies resolutions, npm 7 will print a warning and work around most peer conflicts that exist deep within the package tree, since you can’t fix those anyway. To enforce strictly correct peer dependency resolutions at all levels, use the --strict-peer-deps flag.

Источник — https://github.blog/2021-02-02-npm-7-is-now-generally-available/#peer-dependencies

Если по-русски, как я это всё понял. Есть проблемы с зависимостями между модулями и не все они описаны/документированы. Раньше npm выдавал предупреждения, но с 7й версии начал вываливать ошибки, если обнаруживал несовместимости. Чтобы этого избежать при деплое, надо выполнить описанные команды: деплой пройдёт тогда с WARN. Вот пример портянки:

#14 [build 8/10] RUN npm ci --legacy-peer-deps
90#14 1.505 npm WARN EBADENGINE Unsupported engine {
91#14 1.506 npm WARN EBADENGINE package: '@achrinza/node-ipc@9.2.2',
92#14 1.506 npm WARN EBADENGINE required: { node: '8 || 10 || 12 || 14 || 16 || 17' },
93#14 1.506 npm WARN EBADENGINE current: { node: 'v18.18.2', npm: '9.8.1' }
94#14 1.507 npm WARN EBADENGINE }
95#14 5.289 npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
96#14 5.457 npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
97#14 5.854 npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
98#14 5.856 npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
99#14 5.895 npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
100#14 5.925 npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
101#14 6.215 npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
102#14 6.310 npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
103#14 7.123 npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
104#14 8.464 npm WARN deprecated har-validator@5.1.5: this library is no longer supported
105#14 8.604 npm WARN deprecated html-webpack-plugin@3.2.0: 3.x is no longer supported
106#14 9.608 npm WARN deprecated consolidate@0.15.1: Please upgrade to consolidate v1.0.0+ as it has been modernized with several long-awaited fixes implemented. Maintenance is supported by Forward Email at https://forwardemail.net ; follow/watch https://github.com/ladjs/consolidate for updates and release changelog
107#14 9.980 npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
108#14 10.86 npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
109#14 10.87 npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
110#14 10.91 npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
111#14 11.00 npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
112#14 11.18 npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
113#14 11.37 npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
114#14 11.90 npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
115#14 12.05 npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
116#14 12.11 npm WARN deprecated consolidate@0.16.0: Please upgrade to consolidate v1.0.0+ as it has been modernized with several long-awaited fixes implemented. Maintenance is supported by Forward Email at https://forwardemail.net ; follow/watch https://github.com/ladjs/consolidate for updates and release changelog

Вот такой анализ.

По итогу разработчики в моём случае всё же поправили зависимости и сборка прошла успешно как обычно с npm ci.

Добавить комментарий