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

0.33.3 Throws TypeError: A string was expected #4095

Open
Enngage opened this issue May 7, 2024 · 15 comments
Open

0.33.3 Throws TypeError: A string was expected #4095

Enngage opened this issue May 7, 2024 · 15 comments
Labels

Comments

@Enngage
Copy link

Enngage commented May 7, 2024

Possible bug

Locally everything works fine, but our deployment in Azure (Node 20 LTS, linux) started throwing exceptions such as:

TypeError: A string was expected
2024-05-07T13:07:25.0791187Z 13:07:25 0|abc|     at file:///home/site/wwwroot/dist/abc/server/server.mjs:114:78047
2024-05-07T13:07:25.0812631Z 13:07:25 0|abc|     at new A (file:///home/site/wwwroot/dist/abc/server/polyfills.server.mjs:4:2348)
2024-05-07T13:07:25.0836674Z 13:07:25 0|abc|     at pu.$3e [as _pipeline] (file:///home/site/wwwroot/dist/abc/server/server.mjs:114:78024)
2024-05-07T13:07:25.0857768Z 13:07:25 0|abc|     at pu.v3e [as toBuffer] (file:///home/site/wwwroot/dist/abc/server/server.mjs:114:59649)
2024-05-07T13:07:25.0891412Z 13:07:25 0|abc|     at y3.<anonymous> (file:///home/site/wwwroot/dist/abc/server/server.mjs:160:7917)
2024-05-07T13:07:25.0908622Z 13:07:25 0|abc|     at Generator.next (<anonymous>)
2024-05-07T13:07:25.0924518Z 13:07:25 0|abc|     at file:///home/site/wwwroot/dist/abc/server/chunk-OLFPQWYA.mjs:2:1616
2024-05-07T13:07:25.0946588Z 13:07:25 0|abc|     at new A (file:///home/site/wwwroot/dist/abc/server/polyfills.server.mjs:4:2348)
2024-05-07T13:07:25.0995308Z 13:07:25 0|abc|     at L (file:///home/site/wwwroot/dist/abc/server/chunk-OLFPQWYA.mjs:2:1436)
2024-05-07T13:07:25.1019244Z 13:07:25 0|abc|     at y3.convertImageToWebpAsync (file:///home/site/wwwroot/dist/abc/server/server.mjs:160:7553)

Everything works perfectly fine with 0.33.0. The dependency version change is the only difference in deployments. It works perfectly fine locally even with latest version 0.33.0.

Not sure if I can provide more information since it's a bit unfortunate error and only reproducable within Azure.

@Enngage Enngage added the triage label May 7, 2024
@lovell lovell added question and removed triage labels May 7, 2024
@lovell
Copy link
Owner

lovell commented May 7, 2024

Nothing in the stack trace provided here is from within sharp itself.

If you still require help you'll need to provide some sample code that allows someone else to reproduce or at least better understand how you're trying to use sharp.

@Enngage
Copy link
Author

Enngage commented May 7, 2024

Thanks for a quick response.

Yeah, I know, it's minimized code (sorry). Sadly I can't get full trace from our deployed instance.

All calls to sharp fail, this is an example of one such instance:

import sharp from 'sharp';

// inputImage = Buffer

const webpImage = await sharp(inputImage)
    .webp({
	quality: 100,
	alphaQuality: 100,
	lossless: true,
})
.toBuffer();

The exception happens right here (I've added some logs right before & after the code above to be sure)

Nothing fancy. As I mentioned, it works perfectly fine locally, and in Azure on version 0.33.0. I did a test deploy by only changing 0.33.0 to 0.33.3 and this error started happening again. Changing back fixes it.

Really not sure what's going on and I'm fine with staying on older version, but figured I could post it here just in case others encounter(ed) same issue.

@lovell
Copy link
Owner

lovell commented May 7, 2024

polyfills.server.mjs

My best guess would be that logic in your bundling step is erroneously polyfilling (i.e. monkey-patching) something fundamental, perhaps Object or Buffer.

Please can you try 0.33.1 and 0.33.2 to help narrow this down.

@Enngage
Copy link
Author

Enngage commented May 9, 2024

I don't think the bundling should be a problem here as it works with older versions. It's an Angular 17 SSR app (just FYI). This code is executed strictly on server (Node 20 - LTS on Linux).

I did several new releases one by one:

0.30.0 -> Works
0.30.1 -> Works
0.30.2 -> Works
0.30.3 -> Fails
Downgrade to 0.30.2 -> Works again

The only changes between these releases are sharp versions in package.json.

@lovell
Copy link
Owner

lovell commented May 9, 2024

It's an Angular 17 SSR app... This code is executed strictly on server (Node 20 - LTS on Linux).

My best guess remains that something is being polyfilled in an unexpected or broken way. Can you prevent Angular from generating polyfills for the server side code? If not, what objects and functions are being polyfilled by dist/abc/server/polyfills.server.mjs?

Looking at the changes to sharp between v0.33.2 and v0.33.3 there is 7bc74fe that introduces the use of structuredClone, which is the sort of thing that I might imagine could be pollyfilled in a non-standard way.

@rnenjoy
Copy link

rnenjoy commented May 10, 2024

Getting the same error on my apollo server.

await sharp(tmpFilePath) .resize({ width: 1500, height: 1500, fit: 'inside' }) .jpeg({ quality: 90 }) .toFile(tmpFileResizedPath)

both variables are paths /srv/http/blabla.jpg etc

error: TypeError: A string was expected at /srv/http/dev-net23/backend/node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/lib/output.js:1534:15 at new Promise (<anonymous>) at Sharp._pipeline (/srv/http/dev-net23/backend/node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/lib/output.js:1533:14) at Sharp.toFile (/srv/http/dev-net23/backend/node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/lib/output.js:90:17) at Object.uploadAppWorkshopPicture (file:///srv/http/dev-net23/backend/src/modules/app/resolvers.js:35:6) { path: [ 'uploadAppWorkshopPicture' ], locations: [ { line: 2, column: 3 } ], extensions: [Object: null prototype] {}

@lovell
Copy link
Owner

lovell commented May 10, 2024

Please can you create a standalone repo with minimal dependencies that allows someone else to reproduce.

@rnenjoy
Copy link

rnenjoy commented May 10, 2024

Please can you create a standalone repo with minimal dependencies that allows someone else to reproduce.

Yes i will try to do that! I'm not that experienced in repos. Do i do that on github or some pastebin variant?

@lovell
Copy link
Owner

lovell commented May 10, 2024

Do i do that on github

Yes please, that would be ideal, I'd expect to see a package.json file with dependencies, a single test image and a single JS file that someone else can use to reproduce.

@lovell
Copy link
Owner

lovell commented May 16, 2024

@Enngage @rnenjoy Are either of you able to create a minimal repo that allows someone else to reproduce?

@rnenjoy
Copy link

rnenjoy commented May 18, 2024

@Enngage @rnenjoy Are either of you able to create a minimal repo that allows someone else to reproduce?

Sorry for late reply. I was working on the minimal repo but didnt mange to get the error. Then i saw that i now used 0.33.4. And the problem seems to be gone? So no need to work any more on it? :)

@lovell
Copy link
Owner

lovell commented Jun 1, 2024

@Enngage Were you able to make any progress with this?

@Enngage
Copy link
Author

Enngage commented Jun 1, 2024

Hey @lovell,

I've tried upgrading to 0.33.4, but that didn't help in my case. Honestly, the only way I can reproduce it is by pushing this to Azure (Node 20 LTS, linux). Even the simplest example fails there, no setup needed, just try to include import and call sharp and it fails.

@lovell
Copy link
Owner

lovell commented Jun 1, 2024

Thanks for the update.

Even the simplest example fails there, no setup needed

When you say "simplest example", is this with sharp as the only dependency, or are you still using Angular and therefore at the mercy of its polyfills.server.mjs?

Sadly, without a complete, minimal repo declaring the dependencies, code and build steps that will allow someone else to reproduce, there's not a lot anyone can do to help.

@rnenjoy
Copy link

rnenjoy commented Jun 1, 2024

Maybe my started working with 34 is because I upgraded to node 22 aswell ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants