Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails when prerendering using "sharp" package #5056

Open
pauldiloreto opened this issue Jun 6, 2023 · 1 comment
Open

Build fails when prerendering using "sharp" package #5056

pauldiloreto opened this issue Jun 6, 2023 · 1 comment
Labels
type: bug code to address defects in shipped code

Comments

@pauldiloreto
Copy link

Describe the bug

Even though netlify build and npm run build works locally, the Netlify build fails in production when pushing a website that is prerendering, using the sharp package to generate image placeholders on the serverside.

I am experiencing this in a sveltekit website, configured to prerender every page. It works without prerendering or prendering, but with the "sharp" code commented out. And, as mentioned, everything works perfectly locally.

The example server code is as such:

		const response = await fetch(imageUrl);
		const imageBuffer = await response.arrayBuffer();
		const image = sharp(imageBuffer);
		const buffer = await image
			.resize(10)
			.jpeg({
				quality: 50,
				progressive: true,
				optimiseScans: true,
				chromaSubsampling: '4:2:0',
				trellisQuantisation: true,
				quantisationTable: 2
			})
			.toBuffer({ resolveWithObject: false });
		return `data:image/jpeg;base64,${buffer.toString('base64')}`;

Steps to reproduce

  1. Use sharp somewhere in server side code, in a sveltekit project.
  2. Configure this route to prerender (export const prerender = true).
  3. Use either @sveltejs/adapter-netlify or @sveltejs/adapter-static in svelte.config.js.
  4. Push changes to origin, triggering a continuous deploy.
  5. Build fails in Netlify.

Configuration

[build]
command = "npm run build"
publish = "build"

Deploy logs

1:09:54 PM: Netlify Build
1:09:54 PM: ────────────────────────────────────────────────────────────────
1:09:54 PM: ​
1:09:54 PM: ❯ Version
1:09:54 PM: @netlify/build 29.11.8
1:09:54 PM: ​
1:09:54 PM: ❯ Flags
1:09:54 PM: baseRelDir: true
1:09:54 PM: buildId: 647f92850f209f00082237d1
1:09:54 PM: deployId: 647f92850f209f00082237d3
1:09:54 PM: ​
1:09:54 PM: ❯ Current directory
1:09:54 PM: /opt/build/repo
1:09:54 PM: ​
1:09:54 PM: ❯ Config file
1:09:54 PM: /opt/build/repo/netlify.toml
1:09:54 PM: ​
1:09:54 PM: ❯ Context
1:09:54 PM: production
1:09:54 PM: ​
1:09:54 PM: build.command from netlify.toml
1:09:54 PM: ────────────────────────────────────────────────────────────────
1:09:54 PM: ​
1:09:54 PM: $ npm run build
1:09:55 PM: > carolyn-portfolio@0.0.1 build
1:09:55 PM: > vite build
1:09:55 PM: ▲ [WARNING] Cannot find base config file "./.svelte-kit/tsconfig.json" [tsconfig.json]
1:09:55 PM: tsconfig.json:2:12:
1:09:55 PM: 2 │ "extends": "./.svelte-kit/tsconfig.json",
1:09:55 PM: ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1:09:56 PM: vite v4.3.9 building SSR bundle for production...
1:09:56 PM: transforming...
1:09:57 PM: ✓ 104 modules transformed.
1:09:58 PM: rendering chunks...
1:09:58 PM: vite v4.3.9 building for production...
1:09:58 PM: transforming...
1:09:59 PM: ✓ 88 modules transformed.
1:09:59 PM: Generated an empty chunk: "7".
1:09:59 PM: rendering chunks...
1:10:00 PM: computing gzip size...
1:10:00 PM: .svelte-kit/output/client/_app/version.json 0.03 kB │ gzip: 0.05 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/karla-latin-ext-400-normal.36edfb66.woff2 5.02 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/old-standard-tt-vietnamese-400-normal.4b051f97.woff 5.28 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/karla-latin-ext-400-normal.0407b96c.woff 7.28 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/old-standard-tt-vietnamese-400-normal.9d2e527a.woff2 7.30 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/old-standard-tt-cyrillic-400-normal.6ec9c3c3.woff 10.02 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/karla-latin-400-normal.bb02ccb2.woff2 11.28 kB
1:10:00 PM: .svelte-kit/output/client/vite-manifest.json 12.37 kB │ gzip: 1.34 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/old-standard-tt-cyrillic-ext-400-normal.f1d0771a.woff 12.79 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/old-standard-tt-cyrillic-400-normal.ac77a96f.woff2 14.18 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/karla-latin-400-normal.bdc40c74.woff 15.09 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/old-standard-tt-latin-ext-400-normal.7c1ae27c.woff 15.95 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/old-standard-tt-latin-400-normal.51523ac8.woff 16.53 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/old-standard-tt-cyrillic-ext-400-normal.ef4f29f8.woff2 18.40 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/old-standard-tt-latin-400-normal.b6ad8f48.woff2 22.84 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/old-standard-tt-latin-ext-400-normal.4370dfbb.woff2 25.92 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/LayoutContainer.9331432b.css 0.15 kB │ gzip: 0.12 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/LayoutImage.49993c8e.css 0.16 kB │ gzip: 0.12 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/1.0e1cf69c.css 0.17 kB │ gzip: 0.14 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/Background.4517e7dc.css 0.29 kB │ gzip: 0.19 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/Projects.1fc19b6d.css 0.86 kB │ gzip: 0.38 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/3.61249c9f.css 1.01 kB │ gzip: 0.41 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/2.b8952ac7.css 1.29 kB │ gzip: 0.41 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/4.0e3b6401.css 1.47 kB │ gzip: 0.53 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/Filter.ccda83f2.css 2.23 kB │ gzip: 0.77 kB
1:10:01 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/6.e22ea103.css 5.43 kB │ gzip: 1.12 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/assets/0.c8a2987d.css 10.77 kB │ gzip: 2.71 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/chunks/7.4ed993c7.js 0.00 kB │ gzip: 0.02 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/chunks/stores.31aa9048.js 0.07 kB │ gzip: 0.09 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/chunks/index.059e2550.js 0.45 kB │ gzip: 0.31 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/chunks/LayoutContainer.4fdc6d2f.js 0.72 kB │ gzip: 0.48 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/chunks/Background.34dcb121.js 0.93 kB │ gzip: 0.58 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/nodes/1.eaf8156f.js 1.00 kB │ gzip: 0.57 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/nodes/5.e1c64912.js 1.08 kB │ gzip: 0.67 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/chunks/singletons.c4260443.js 2.46 kB │ gzip: 1.26 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/chunks/LayoutImage.ad56a46b.js 2.76 kB │ gzip: 1.34 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/nodes/3.4b8f2b4e.js 2.82 kB │ gzip: 1.37 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/chunks/Projects.32261969.js 2.91 kB │ gzip: 1.40 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/nodes/2.466996bb.js 5.71 kB │ gzip: 2.83 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/entry/app.8353f8c0.js 7.56 kB │ gzip: 2.58 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/nodes/6.d65356ae.js 7.89 kB │ gzip: 2.99 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/nodes/4.bf29e1a1.js 8.54 kB │ gzip: 3.33 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/chunks/Filter.df29c5af.js 12.33 kB │ gzip: 4.58 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/chunks/index.607d4385.js 13.27 kB │ gzip: 5.66 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/nodes/0.d7b6197e.js 14.25 kB │ gzip: 5.66 kB
1:10:00 PM: .svelte-kit/output/client/_app/immutable/entry/start.19990033.js 23.99 kB │ gzip: 9.52 kB
1:10:00 PM: ✓ built in 1.78s
1:10:00 PM: Error:
1:10:00 PM: Something went wrong installing the "sharp" module
1:10:00 PM: Module did not self-register: '/opt/build/repo/node_modules/sharp/build/Release/sharp-linux-x64.node'.
1:10:00 PM: Possible solutions:
1:10:00 PM: - Using worker threads? See https://sharp.pixelplumbing.com/install#worker-threads
1:10:00 PM: - Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
1:10:00 PM: - Install for the current linux-x64 runtime: "npm install --platform=linux --arch=x64 sharp"
1:10:00 PM: - Consult the installation documentation: https://sharp.pixelplumbing.com/install
1:10:00 PM: at Object. (/opt/build/repo/node_modules/sharp/lib/sharp.js:37:9)
1:10:00 PM: at Module._compile (node:internal/modules/cjs/loader:1254:14)
1:10:00 PM: at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
1:10:00 PM: at Module.load (node:internal/modules/cjs/loader:1117:32)
1:10:00 PM: at Module._load (node:internal/modules/cjs/loader:958:12)
1:10:00 PM: at Module.require (node:internal/modules/cjs/loader:1141:19)
1:10:00 PM: at require (node:internal/modules/cjs/helpers:110:18)
1:10:00 PM: at Object. (/opt/build/repo/node_modules/sharp/lib/constructor.js:11:1)
1:10:00 PM: at Module._compile (node:internal/modules/cjs/loader:1254:14)
1:10:00 PM: at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
1:10:00 PM: node:internal/event_target:1012
1:10:00 PM: process.nextTick(() => { throw err; });
1:10:00 PM: ^
1:10:00 PM: Error: 500 /
1:10:00 PM: To suppress or handle this error, implement handleHttpError in https://kit.svelte.dev/docs/configuration#prerender
1:10:00 PM: at file:///opt/build/repo/node_modules/@sveltejs/kit/src/core/config/options.js:211:13
1:10:00 PM: at file:///opt/build/repo/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:64:25
1:10:00 PM: at save (file:///opt/build/repo/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:403:4)
1:10:00 PM: at visit (file:///opt/build/repo/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:236:3)
1:10:00 PM: Emitted 'error' event on Worker instance at:
1:10:00 PM: at [kOnErrorMessage] (node:internal/worker:300:10)
1:10:00 PM: at [kOnMessage] (node:internal/worker:311:37)
1:10:00 PM: at MessagePort. (node:internal/worker:212:57)
1:10:00 PM: at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
1:10:00 PM: at exports.emitMessage (node:internal/per_context/messageport:23:28)
1:10:00 PM: Node.js v18.16.0
1:10:00 PM: ​
1:10:00 PM: "build.command" failed
1:10:00 PM: ────────────────────────────────────────────────────────────────
1:10:00 PM: ​
1:10:00 PM: Error message
1:10:00 PM: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
1:10:00 PM: ​
1:10:00 PM: Error location
1:10:00 PM: In build.command from netlify.toml:
1:10:00 PM: npm run build
1:10:00 PM: ​
1:10:00 PM: Resolved config
1:10:00 PM: build:
1:10:00 PM: command: npm run build
1:10:00 PM: commandOrigin: config
1:10:00 PM: environment:
1:10:00 PM: - CONTENTFUL_ACCESS_TOKEN
1:10:00 PM: - CONTENTFUL_SPACE_ID
1:10:00 PM: publish: /opt/build/repo/build
1:10:00 PM: publishOrigin: config
1:10:01 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:10:01 PM: Failing build: Failed to build site
1:10:01 PM: Finished processing build request in 18.769s

@pauldiloreto pauldiloreto added the type: bug code to address defects in shipped code label Jun 6, 2023
@pauldiloreto
Copy link
Author

Anyone have any feedback on this issue?
For more information, I have confirmed that this builds locally with netlify build. It fails on netlify cloud using the latest build image available: "Ubuntu Focal 20.04".
Again, it build succeeds when turning off prerender flag in Sveltekit. However, I am expecting to be able to build using sharp logic in server functions, as this works locally without issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

1 participant