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

🐛 BUG: Astro/image getImage doesn't work in .ts file #4161

Closed
1 task done
nicolasverlhiac opened this issue Aug 4, 2022 · 6 comments · Fixed by #4279
Closed
1 task done

🐛 BUG: Astro/image getImage doesn't work in .ts file #4161

nicolasverlhiac opened this issue Aug 4, 2022 · 6 comments · Fixed by #4279
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@nicolasverlhiac
Copy link

nicolasverlhiac commented Aug 4, 2022

What version of astro are you using?

v1.0.0-rc.4

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

yarn

What operating system are you using?

Mac (M1)

Describe the Bug

Hi @tony-sull 👋 (issue following our discussion yesterday)

@astrojs/image: 0.3.0

When is use getImage in a .ts context, and when I run yarn build or yarn dev I get this error message :

You can mark the path "virtual:image-loader" as external to exclude it from the bundle, which will remove this error. You can also add ".catch()" here to handle this failure at run-time instead of bundle-time.

Test it :

import { getImage } from '@astrojs/image';

export async function get() {
  const img = await getImage({
      "src": `https://api.weavescan.dev/storage/uploads/2022/08/02/android-chrome-512x512_uid_62e9856669173.png`,
      "width": 50,
      "height": 50,
      "format": "webp"
    });
    return {
      body: JSON.stringify(
        {"src":img.src} 
      )
  };
 }

Link to Minimal Reproducible Example

N/A

Participation

  • I am willing to submit a pull request for this issue.
@nicolasverlhiac
Copy link
Author

nicolasverlhiac commented Aug 4, 2022

Build message :

{
errors: [
    {
      detail: undefined,
      id: '',
      location: {
        column: 42,
        file: 'node_modules/@astrojs/image/dist/lib/get-image.js',
        length: 22,
        line: 72,
        lineText: '    const { default: mod } = await import("virtual:image-loader");',
        namespace: '',
        suggestion: ''
      },
      notes: [
        {
          location: null,
          text: 'You can mark the path "virtual:image-loader" as external to exclude it from the bundle, which will remove this error. You can also add ".catch()" here to handle this failure at run-time instead of bundle-time.'
        }
      ],
      pluginName: '',
      text: 'Could not resolve "virtual:image-loader"'
    }
  ]
}

@FredKSchott FredKSchott added - P4: important Violate documented behavior or significantly impacts performance (priority) - P3: minor bug An edge case that only affects very specific usage (priority) s2-medium and removed - P4: important Violate documented behavior or significantly impacts performance (priority) labels Aug 5, 2022
@oliverpool
Copy link
Contributor

I have the same error message in a .js flle (and a local image). The astro dev runs fine, however the astro build fails.

@nicolasverlhiac
Copy link
Author

Hi,

For information, I redid tests with the following versions :
@astrojs/image: 0.3.3
astro: 1.0.2

And the issue persists.

@natemoo-re
Copy link
Member

Hey @oliverpool and @nicolasverlhiac, just ran into a similar issue. Can you confirm that the image() integration is actually added to your astro.config.mjs file?

#4257 (comment)

@nicolasverlhiac
Copy link
Author

Hey @natemoo-re, I confirm that I already have these settings in my astro.config.mjs

@oliverpool
Copy link
Contributor

I think I found my issue: I was using getImage at the top of my file, and not inside the export const get = ... function!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants