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

Wrong version of 'Sharp' when running on Vercel #1570

Open
Jacob-Branch opened this issue Nov 26, 2024 · 3 comments
Open

Wrong version of 'Sharp' when running on Vercel #1570

Jacob-Branch opened this issue Nov 26, 2024 · 3 comments
Labels
bug Something isn't working dependencies Pull requests and issues related to dependencies external Problems or limitations traced back to other tools. package:functions

Comments

@Jacob-Branch
Copy link

When running gltf-transform on a Vercel instance (linux-x64) there is an error being thrown that states that the wrong version of sharp is being used. There is already a version of sharp in the project that works fine but as soon as you import gltf-transform and make a request to the backend, you get this error in return.

Error: Could not load the "sharp" module using the linux-x64 runtime
Possible solutions:
- Ensure optional dependencies can be installed:
    npm install --include=optional sharp
- Ensure your package manager supports multi-platform installation:
    See https://sharp.pixelplumbing.com/install#cross-platform
- Add platform-specific dependencies:
    npm install --os=linux --cpu=x64 sharp
- Consult the installation documentation:
    See https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (/var/task/node_modules/ndarray-pixels/node_modules/sharp/lib/sharp.js:113:9)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Object..js (node:internal/modules/cjs/loader:1689:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function.<anonymous> (node:internal/modules/cjs/loader:1128:12)
    at /opt/rust/nodejs.js:1:12062
    at Function.Rr (/opt/rust/nodejs.js:1:12436)
    at e.<computed>.ve._load (/opt/rust/nodejs.js:1:12032)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)

Function where the issue was encountered:

export const compressGltf = async (geometryBuffer: Buffer): Promise<Buffer> => {
  try {
    const gltfUint8Array = new Uint8Array(geometryBuffer);

    const decoderModule = await draco3d.createDecoderModule();
    const encoderModule = await draco3d.createEncoderModule();

    const io = new NodeIO()
      .registerExtensions(ALL_EXTENSIONS)
      .registerDependencies({
        'draco3d.decoder': decoderModule,
        'draco3d.encoder': encoderModule,
      });

    const document = await io.readBinary(gltfUint8Array);

    document.transform(
      draco({
        decodeSpeed: 1,
        encodeSpeed: 1,
      }),
      dedup({ propertyTypes: [PropertyType.MESH], keepUniqueNames: true }),
      prune({
        propertyTypes: [PropertyType.MATERIAL],
        keepExtras: true,
      }),
      center({ pivot: 'center' }),
    );

    const glbBuffer = await io.writeBinary(document);

    return Buffer.from(glbBuffer);
  } catch (error) {
    console.error('Error during Draco compression or decoding:', error);
    throw error;
  }
};
  • Version: 4.1.0
  • Environment: Next.js server running in Vercel
@Jacob-Branch Jacob-Branch added the bug Something isn't working label Nov 26, 2024
@donmccurdy
Copy link
Owner

donmccurdy commented Nov 26, 2024

There is already a version of sharp in the project that works fine...

Do you know which version(s) of Sharp are installed? And whether matching the versions, or adding resolutions, can avoid the issue? And which glTF Transform packages are you using? Not @gltf-transform/cli, correct? I'm not sure that the CLI package will run in Vercel, but the others should.

Possibly related:

@Jacob-Branch
Copy link
Author

We are using [email protected] with --include=optional and for gltf transform we are using core, extensions, and functions. Matching versions didn't work because [email protected] doesn't run properly so the most wide spread solution i have seen is using [email protected]. I will try upgrading to next@ 15.0.3 as per the Issue that you linked, hopefully that solves the issue.

@donmccurdy
Copy link
Owner

Hmm I see. Perhaps it'd be possible to make 'sharp' a peer dependency of /functions rather than a direct dependency at some point. But I'm not too familiar with the differences between v0.32 and v0.33. I think v0.33 should be 'possible' to run in Vercel — the Sharp folks documented quite a lot of information at https://sharp.pixelplumbing.com/install — but it may also require newer versions of yarn/npm/pnpm or other orthogonal updates, because of the WASM pieces.

@donmccurdy donmccurdy added dependencies Pull requests and issues related to dependencies external Problems or limitations traced back to other tools. labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests and issues related to dependencies external Problems or limitations traced back to other tools. package:functions
Projects
None yet
Development

No branches or pull requests

2 participants