Runner does not continue onto next script after npm build

I’m taking the script from Vitejs documentation.

The only thing I am changing is the node version because it appears Node v16 is not compatible with stylus package - so I’m using Node v17.9.0.

I have tried the shared runners at first and, then, assigned my own registered runner. I have also tried removing the last script ‘- cp -a dist/. public/’ and artifacts. This does not help.

The npm buld completes, but the cp command does not even start. Processing time has taken upwards of 20mins at which point I cancel the job.

What else can I try? Any help is much appreciated.

Here is a sample log:

e[0KRunning with gitlab-runner 15.9.0~beta.115.g598a7c91 (598a7c91)e[0;m
e[0K  on blue-4.shared.runners-manager.gitlab.com/default J2nyww-s, system ID: s_5425356d8adfe[0;m
e[0K  feature flags: FF_USE_IMPROVED_URL_MASKING:truee[0;m
section_start:1683437452:prepare_executor
e[0Ke[0Ke[36;1mPreparing the "docker+machine" executore[0;me[0;m
e[0KUsing Docker executor with image node:17.9.0 ...e[0;m
e[0KPulling docker image node:17.9.0 ...e[0;m
e[0KUsing docker image sha256:408223647013f0f06b9235315bfa7a33dcc7f28cacf32fdaa519f2faf860535b for node:17.9.0 with digest node@sha256:e44a474a494c84a059b50d81d93c4bc281cf66d27b1cab5210b1bb657c6750a5 ...e[0;m
section_end:1683437487:prepare_executor
e[0Ksection_start:1683437487:prepare_script
e[0Ke[0Ke[36;1mPreparing environmente[0;me[0;m
Running on runner-j2nyww-s-project-24054724-concurrent-0 via runner-j2nyww-s-shared-1683437415-6aac42ab...
section_end:1683437490:prepare_script
e[0Ksection_start:1683437490:get_sources
e[0Ke[0Ke[36;1mGetting source from Git repositorye[0;me[0;m
e[32;1m$ eval "$CI_PRE_CLONE_SCRIPT"e[0;m
e[32;1mFetching changes with git depth set to 50...e[0;m
Initialized empty Git repository in /builds/apo11oCreed/mbta-subway-train-game/.git/
e[32;1mCreated fresh repository.e[0;m
e[32;1mChecking out 9d11646d as detached HEAD (ref is master)...e[0;m

e[32;1mSkipping Git submodules setupe[0;m
section_end:1683437491:get_sources
e[0Ksection_start:1683437491:restore_cache
e[0Ke[0Ke[36;1mRestoring cachee[0;me[0;m
e[32;1mChecking cache for npm-0fa164cd20b98dda4b572e14337f12049d0a8db3-2...e[0;m
e[0;33mWARNING: file does not exist                      e[0;m 
e[0;33mFailed to extract cachee[0;m
section_end:1683437492:restore_cache
e[0Ksection_start:1683437492:step_script
e[0Ke[0Ke[36;1mExecuting "step_script" stage of the job scripte[0;me[0;m
e[0KUsing docker image sha256:408223647013f0f06b9235315bfa7a33dcc7f28cacf32fdaa519f2faf860535b for node:17.9.0 with digest node@sha256:e44a474a494c84a059b50d81d93c4bc281cf66d27b1cab5210b1bb657c6750a5 ...e[0;m
e[32;1m$ npm installe[0;m
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
npm WARN deprecated flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated postcss-cssnext@3.1.1: 'postcss-cssnext' has been deprecated in favor of 'postcss-preset-env'. Read more at https://moox.io/blog/deprecating-cssnext/
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.

added 346 packages, and audited 347 packages in 14s

33 packages are looking for funding
  run `npm fund` for details

34 vulnerabilities (32 moderate, 2 high)

To address issues that do not require attention, run:
  npm audit fix

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.
e[32;1m$ npm run builde[0;m

> mbta-subway-train-game@1.0.0 build
> vite build

e[36mvite v3.2.5 e[32mbuilding for production...e[36me[39m
e[36m
watching for file changes...e[39m
e[36m
build started...e[39m
transforming...
e[32m✓e[39m 7 modules transformed.
rendering chunks...
e[90me[37me[2mdist/e[22me[90me[39me[32mimg/030221_mbta_t-e1853eb9.svg  e[39m e[2m0.21 KiBe[22m
e[90me[37me[2mdist/e[22me[90me[39me[32mindex.html                      e[39m e[2m2.66 KiBe[22m
e[90me[37me[2mdist/e[22me[90me[39me[36mjs/index-1dfeb41d.js            e[39m e[2m17.88 KiB / gzip: 5.67 KiBe[22m
e[90me[37me[2mdist/e[22me[90me[39me[90mjs/index-1dfeb41d.js.map        e[39m e[2m51.07 KiBe[22m
e[90me[37me[2mdist/e[22me[90me[39me[35mcss/style-e34daa2b.css          e[39m e[2m5.72 KiB / gzip: 1.26 KiBe[22m
e[36mbuilt in 762ms.e[39m

When you remove the - npm run build line from the script, does it still hangs?

If not, what is the definition of the npm script named “build” in your package configuration?

I removed the npm run build line from the script and it succeeded. Here are the definitions of the scripts in package.json

"scripts": {
		"dev": "vite --port 8080 --host",
		"build": "vite build",
		"serve": "npm run build && vite preview"
	},

Is this a config issue with vite or rollup?

please modify the “build” script a little, so that we have the shell reporting back if it finishes and with which exit status:

   "build": "vite build; printf 'vite build exited: %d\\n' \"$?\" ",

then try again.

I see no rollup, therefore if then vite. But too early too say. Right now it looks to me that the npm “build” script does not finish, lets double check that first.

@hakre, made that modification and the pipeline still hangs at npm run build although I do see this message in the last line before cancelling.
built in 832ms.
Since this does not finish, shell does not report back.

hmm, try with node 20 image?

@hakre, thank you. Changing the image to node v20 did not appear to make any difference. I found a lead that suggested the build will not complete due to Vite default config of watch property. The build completed after I set this property to false.

Then, I tested .gitlab-ci.yml for the pipeline and the job completed there as well.

// vite.config.js
export default {
    // config options
    base: '/game/',
    publicDir: 'public',
    build: {
        watch: false,
        outDir: 'dist',
        cssCodeSplit: true,
        sourcemap: 'inline',
        rollupOptions: {
			output: {
				assetFileNames: (assetInfo) => {
					let extType = assetInfo.name.split('.').at(1);
					if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
						extType = 'img';
					}
					return `${extType}/[name]-[hash][extname]`;
				},
				chunkFileNames: 'js/[name]-[hash].js',
				entryFileNames: 'js/[name]-[hash].js',
			},
		},
      }
  }

Ah! I’ve seen that in the very beginning in your logs (that it is watching)

> vite build

e[36mvite v3.2.5 e[32mbuilding for production...e[36me[39m
e[36m
watching for file changes...e[39m
e[36m

but then thought if it wasn’t an issue in the previous node.js image, it is likely not the culprit here and I didn’t want to speculate about it. Just as feedback, can happen.

So in the end, this makes sense in terms of cause and fix.

But why doesn’t vite detect this it is running in CI or during the build script? It makes no sense to have the file watcher active for that.

And not so super-fluid with npm but there should be some timeout option available so that you can encode your expectation how long a npm script invocation should take at maximum so that you can make it fail faster. That pattern you can apply to different things in the build then and is very useful for remote builds like typically the case with Gitlab CI/CD.