-
Notifications
You must be signed in to change notification settings - Fork 274
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
TypeError: Cannot read property '_img' of undefined #258
Comments
I had a similar issue with my 404 page. Duplicate of #249 |
Hi @lucadalli. In fact that stage (plugin entry) server context is not available that's why you are getting this error. Proper method is using export default function ({ $img, beforeNuxtRender }) {
if (process.static) {
beforeNuxtRender(() => {
$img("https://via.placeholder.com/350x150", {
width: 100
});
});
}
} See my fork: https://codesandbox.io/s/lively-feather-uwhmz?file=/plugins/image.server.js (link outdated) Regardless I will try to add a guard when ssrContext is not available (it won't work but also don't crash and possibly fixing #249) |
Guard also added in |
@pi0, it's working as intended with |
I am attempting to resize images during
nuxt.generate
by callingcontext.$img
from a server plugin.The plugin is intentionally naïve and runs on every request to keep the demo minimal.
I am facing the error below:
Reproduction steps:
yarn run generate
in terminalThe text was updated successfully, but these errors were encountered: