Errors building js website with sharp package on Pages

Hi, in the last two/three days I’m experiencing an issue building next.js (static and edge) websites on Cloudflare Pages. The build fails in the link step, this is the relevant log:

17:57:27.900	➤ YN0000: ┌ Link step
17:57:51.843	➤ YN0007: │ sharp@npm:0.32.3 must be built because it never has been before or the last one failed
17:57:51.843	➤ YN0007: │ esbuild@npm:0.15.18 must be built because it never has been before or the last one failed
17:57:51.844	➤ YN0007: │ sharp@npm:0.32.1 must be built because it never has been before or the last one failed
17:57:51.844	➤ YN0007: │ esbuild@npm:0.16.3 must be built because it never has been before or the last one failed
17:57:51.844	➤ YN0007: │ better-sqlite3@npm:8.4.0 must be built because it never has been before or the last one failed
17:57:51.845	➤ YN0007: │ workerd@npm:1.20230710.0 must be built because it never has been before or the last one failed
17:57:52.422	➤ YN0000: │ sharp@npm:0.32.3 STDOUT sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.14.2/libvips-8.14.2-linux-x64.tar.br
17:57:52.530	➤ YN0000: │ sharp@npm:0.32.1 STDOUT sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.14.2/libvips-8.14.2-linux-x64.tar.br
17:57:53.011	➤ YN0000: │ sharp@npm:0.32.1 STDOUT sharp: Integrity expected: sha512-wjCKmWfBb0uz1UB7rPDLvO0s+VWuoAY/Vv/YGCRFEQUkdSLQUgHExrOMMbOM3FleuYfQqznDYCXXphkl7X44+w==
17:57:53.012	➤ YN0000: │ sharp@npm:0.32.1 STDOUT sharp: Integrity received: sha512-3DK3McLL6ibzTDxqVjRQ38usF8cbcX4eZ4VBPzYPGvo1y27GIThTnB9tLTufA8Y72GBiRmxT9lo7A7tfvqp2Zg==
17:57:53.015	➤ YN0000: │ sharp@npm:0.32.1 STDERR sharp: Installation error: Integrity check failed for linux-x64
17:57:53.015	➤ YN0000: │ sharp@npm:0.32.1 STDOUT sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
17:57:53.148	➤ YN0009: │ sharp@npm:0.32.1 couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-9d85e02b/build.log)
17:57:53.332	➤ YN0000: │ sharp@npm:0.32.3 STDOUT sharp: Integrity check passed for linux-x64
17:57:53.939	➤ YN0000: └ Completed in 26s 38ms
17:57:54.094	➤ YN0000: Failed with errors in 1m 39s

It seems the sharp package needs some library that’s not installed on some build machines, since after retrying the deployment two-three times the build completes. This happens using the version 2 build system, both with plug’n’play linker and node-modules.

Thanks

I think this is due to some pre-configuration commands in the new V2 Build system,
try to read the logs to see what’s the problem,
this is my case here but for Jekyll, it may help you…

Thanks for your message, but this is not the case. The build worked flawlessly up to thursday last week and began failing only on friday. Also, the fail is intermittent, so this is related to some build servers having a slightly different configuration than the one where the build works.

Same issue, gatsby.js using sharp.:

21:31:00.913	npm WARN cleanup Failed to remove some directories [
21:31:00.913	npm WARN cleanup   [
21:31:00.914	npm WARN cleanup     '/opt/buildhome/repo/node_modules/gatsby-transformer-sharp/node_modules/sharp',
21:31:00.914	npm WARN cleanup     [Error: ENOTEMPTY: directory not empty, rmdir '/opt/buildhome/repo/node_modules/gatsby-transformer-sharp/node_modules/sharp'] {
21:31:00.914	npm WARN cleanup       errno: -39,
21:31:00.914	npm WARN cleanup       code: 'ENOTEMPTY',
21:31:00.914	npm WARN cleanup       syscall: 'rmdir',
21:31:00.914	npm WARN cleanup       path: '/opt/buildhome/repo/node_modules/gatsby-transformer-sharp/node_modules/sharp'
21:31:00.915	npm WARN cleanup     }
21:31:00.915	npm WARN cleanup   ],
21:31:00.915	npm WARN cleanup   [
21:31:00.915	npm WARN cleanup     '/opt/buildhome/repo/node_modules/@graphql-codegen',
21:31:00.915	npm WARN cleanup     [Error: EINVAL: invalid argument, scandir '/opt/buildhome/repo/node_modules/@graphql-codegen/typescript-operations/node_modules/@graphql-codegen/plugin-helpers/cjs'] {
21:31:00.915	npm WARN cleanup       errno: -22,
21:31:00.916	npm WARN cleanup       code: 'EINVAL',
21:31:00.916	npm WARN cleanup       syscall: 'scandir',
21:31:00.916	npm WARN cleanup       path: '/opt/buildhome/repo/node_modules/@graphql-codegen/typescript-operations/node_modules/@graphql-codegen/plugin-helpers/cjs'
21:31:00.916	npm WARN cleanup     }
21:31:00.916	npm WARN cleanup   ]
21:31:00.916	npm WARN cleanup ]
21:31:00.916	npm ERR! code 1
21:31:00.917	npm ERR! path /opt/buildhome/repo/node_modules/gatsby-plugin-manifest/node_modules/sharp
21:31:00.918	npm ERR! command failed
21:31:00.918	npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
21:31:00.919	npm ERR! sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.14.3/libvips-8.14.3-linux-x64.tar.br
21:31:00.919	npm ERR! sharp: Integrity expected: sha512-FKbMBbCcFcSugRtuiTsA6Cov+M2WQ8nzvmmJ5xYYpRg/rsrWvObFT+6x/YBpblur9uXGjGIehjXVZtB3VXc+pg==
21:31:00.919	npm ERR! sharp: Integrity received: sha512-a2ighKEDs86U/oh771nAe5ZY+MbmcIXE1/x+fAtI9mq/6G53WHhYYbWJxxXXhKVM1TUC4SMYHErhOsfiMDJ8eg==
21:31:00.919	npm ERR! sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
21:31:00.919	npm ERR! sharp: Installation error: Integrity check failed for linux-x64
21:31:00.921	
21:31:00.922	npm ERR! A complete log of this run can be found in:
21:31:00.922	npm ERR!     /opt/buildhome/.npm/_logs/2023-07-22T19_29_49_463Z-debug-0.log
21:31:00.992	Error: Exit with error code: 1
21:31:00.992	    at ChildProcess.<anonymous> (/snapshot/dist/run-build.js)
21:31:00.992	    at Object.onceWrapper (node:events:652:26)
21:31:00.992	    at ChildProcess.emit (node:events:537:28)
21:31:00.993	    at ChildProcess._handle.onexit (node:internal/child_process:291:12)
21:31:01.000	Failed: build command exited with code: 1
21:31:01.890	Failed: error occurred while running build command
1 Like

I found what was the issue in my case: I had two slightly different versions of sharp installed, and the two versions interfere with each other when compiling.
Look into your yarn.lock or package-lock.json file and check which versions of sharp are installed, then fix it by changing your direct dependency to match the other one. Or I remember there’s a way to pin a package resolution to a specific version, but I don’t remember how to do it.

1 Like

Still can’t fix it. I have checked and updated the dependencies, same issue. Funny thing, my other gatsby website which is almost 1:1 to this one (cloned and used as a template) works without any problems, with the exact same package.json and src code (just the scss styles are changed).

I am able to build the project on my local machine, it only fails when building via Gitlab Pipeline to Cloudflare Pages.

I got “/bin/sh: 1: gatsby: not found” twice, which is weird too.

If you now see “gatsby: not found” message instead of the build error you made progress nonetheless!

It seems you’re launching a gatsby command directly as your build command, is that right? I think it’s safer to define a “build” script in the package.json and use that to build so the package manager sets the PATH to include freshly built packages inside node_modules or wherever they are in pnpm style installs. Try that.

So I did change the Page’s build command to “npm run build” and pointed it to “gatsby build” in my package.json. Still, using “gatsby build” as the build command was not an issue with the other website that is working just fine.

Also, I did not solved the issue with sharp. I still get the same error most of the times, but not every time (weird). Again, the very same code in a different project works fully…

1 Like

I updated the build settings for the project to use the latest version of node and it worked https://developers.cloudflare.com/pages/platform/language-support-and-tools/