Gatsby-plugin-image: Missing image prop after update to v4 (Netlify) - javascript

We are having an issue with displaying images on Netlify after upgrading Gatsby to V4.
We have been using Netlify for the past 3 years for this project and everything worked fine until we tried to move to V4 of Gatsby.
We are using Strapi with Gatsby and our source plugin is gatsby-source-graphql.
I am also using createRemoteFileNode API to download images and store them locally.
exports.createResolvers = async ({ actions, cache, createNodeId, createResolvers, store, reporter }) => {
const { createNode } = actions;
await createResolvers({
STRAPI_UploadFile: {
imageFile: {
type: 'File',
async resolve(source) {
let sourceUrl = `${source.url}`;
console.log('source Url:', sourceUrl);
return await createRemoteFileNode({
url: encodeURI(sourceUrl),
store,
cache,
createNode,
createNodeId,
reporter,
});
},
},
},
});
};
As you can see above in the gatsby-node.js I have tried to console.log the image urls and they appear in the netlify build process. Could it be that there is something not working as expected in createRemoteFileNode API?
Here is the list of the dependencies.
"dependencies": {
"#headlessui/react": "^1.5.0",
"#heroicons/react": "^1.0.6",
"#loadable/component": "^5.15.0",
"babel-plugin-styled-components": "^1.12.0",
"cross-env": "^7.0.3",
"gatsby": "^4.13.1",
"gatsby-plugin-google-tagmanager": "^4.0.0",
"gatsby-plugin-image": "^2.13.0",
"gatsby-plugin-manifest": "^4.13.0",
"gatsby-plugin-offline": "4.0.0",
"gatsby-plugin-postcss": "^4.0.0",
"gatsby-plugin-react-helmet": "^5.13.0",
"gatsby-plugin-sharp": "^4.13.0",
"gatsby-source-filesystem": "^4.13.0",
"gatsby-source-graphql": "^4.13.0",
"gatsby-transformer-sharp": "^4.13.0",
"iframe-resizer-react": "^1.1.0",
"lodash": "^4.17.21",
"moment-timezone": "^0.5.33",
"prop-types": "15.7.2",
"react": "17.0.1",
"react-carousel": "^4.3.0",
"react-dom": "17.0.1",
"react-helmet": "6.1.0",
"react-markdown": "^6.0.0",
"react-modal": "^3.13.1",
"react-spinners": "^0.11.0",
"styled-components": "^5.3.0",
"use-media": "^1.4.0"
},
The images are working when built locally.
I have also tested this same setup on Gatsby Cloud and everything seemed to be working fine, but due to the business decisions we are unable to migrate to Gatsby Cloud.
Did anyone experience anything similar to this, or do you have maybe a solution to what this would be?
Below is the screenshot of a small portion of our deploy log which is covered with warnings about images missing in gatsby-plugin-image.

It looks like you shouldn't use createRemoteFileNode according to the migration guide. I'd be interested to see how you fixed this. https://www.gatsbyjs.com/docs/reference/release-notes/migrating-from-v3-to-v4/#do-not-create-nodes-in-custom-resolvers
Here's the fix: https://www.gatsbyjs.com/docs/reference/release-notes/migrating-source-plugin-from-v3-to-v4/#2-data-mutations-need-to-happen-during-sourcenodes-or-oncreatenode. Currently implementing myself.

In case anyone needs an answer:
The gatsby-source-graphql doesn't create any nodes (smallest unit of data) in Gatsby's data store so you can't attach/create image nodes directly with it. We had to make this change to support SSR and DSG.
If you’ve used this with gatsby-source-graphql, please switch to Gatsby GraphQL Source Toolkit. Generally speaking you’ll want to create your own source plugin to fully support such use cases.
You'll need to create proper nodes through a source plugin, I think the easiest way would be using gatsby-source-strapi instead of writing your own one.
You might ask yourself: Well, why does it "work" in Gatsby Cloud or locally? It's kinda a race condition and it's not stable or guaranteed that it always succeeds. So you can't rely on this.
Credits: LekoArts #lennart

Related

Why does my Vue+Vite app break as soon as I add firebase analytics import?

I have an app which uses firebase firestore, hosting and authentication and I want to add analytics to it. I'm following the documentation at:
https://firebase.google.com/docs/analytics/get-started?authuser=0&platform=web
When I complete step 3: Add the Analytics JS SDK and initialize Analytics, my app fails to render. No errors, I just see a blank screen instead of the app in the browser.
I found out that the app breaks as soon as I add the first line:
import { getAnalytics } from "firebase/analytics";
What am I doing wrong?
Wait, I'm actually not doing anything...
What... is wrong?
My dependencies:
"dependencies": {
"firebase": "^9.12.1",
"pinia": "^2.0.23",
"vue": "^3.2.37",
"vue-i18n": "^9.2.2",
"vue-router": "^4.1.5"
},
"devDependencies": {
"#vitejs/plugin-vue": "^3.1.0",
"sass": "^1.55.0",
"vite": "^3.1.0"
}

Cannot import and use postcss-simple-vars as a function

I am updating a PostCSS plugin to use PostCSS 8, and I am struggling with this error:
TypeError: vars(...) is not a function
The plugin is referenced in the code like so:
var vars = require('postcss-simple-vars');
...
vars({ only: value })(content);
The plugin was able to make this call before I updated the packages for it, but I'm not sure which one is breaking it. I've tried looking at the source code for postcss-simple-vars but I'm not understanding how this call isn't working.
These are the dependencies BEFORE upgrading:
"dependencies": {
"postcss": "^5.0.0",
"postcss-simple-vars": "^2.0.0"
},
"devDependencies": {
"chai": "3.2.0",
"gulp": "3.9.0",
"gulp-eslint": "0.11.1",
"gulp-mocha": "2.1.3",
"postcss-custom-properties": "^5.0.1"
}
AFTER updating packages:
"dependencies": {
"postcss-simple-vars": "^6.0.3"
},
"peerDependencies": {
"postcss": "^8.0.0"
},
"devDependencies": {
"chai": "4.3.6",
"gulp": "4.0.2",
"gulp-eslint": "6.0.0",
"gulp-mocha": "8.0.0",
"postcss": "^8.0.0",
"postcss-custom-properties": "^12.1.8"
}
The issue seems to be that postcss-simple-vars isn't importing as a function anymore, but I don't know why.
UPDATE
I managed to get it to at least partially compile using this invocation:
const {root} = postcss([vars({ only: value })]).process(content)
My issue with this is that it kind of goes against the principles of PostCSS 8. They mention in their migration guide that you really shouldn't have to import the postcss package anymore to perform operations in a plugin. Though this is technically performing an operation using a separate plugin, it still feels like it could potentially cause performance issues. I don't think I'm smart enough to know how or why though.

XMLHttpRequest not working as expected after package electron

I have a electron project that uses ffi-napi to integrate some cpp code and uses electron-forge / electron-compile to package the app.
Everything works fine when i run "electron-forge start".
My javascript uses XMLHttpRequest to load in some binary data from a custom file format (*.awd). XMLHttpRequest.responseType is "arraybuffer".
The problem is, that once i use "electron-forge package" and run the resulting app, the XMLHttpRequest in my javascript no longer works as expected. It does not throw a error, but the XMLHttpRequest.result is much smaller than it should be, so the parsing of the binary data fails.
This are the versions of electron-forge / electron-compile that i am using:
"dependencies": {
"electron-compile": "^6.4.4",
"electron-squirrel-startup": "^1.0.0",
"ffi-napi": "^2.4.4",
"ref": "^1.3.5"
},
"devDependencies": {
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"electron-forge": "^5.2.4",
"electron-prebuilt-compile": "4.0.0",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-plugin-import": "^2.15.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.12.4"
}
Any help on this would be very much appreciated!
I think i found the solution myself.
The problem is with the "electron-compile" module. After running "electron-forge package" it seem to interfere when loading my custom binary files and prevent them from being loaded correctly via XMLHttpRequest.
The solution seems to use the "addBypassChecker" that comes with the electron-compile package to ignore files to be recompiled by electron-compiled if they are not part of the App.
import { app } from 'electron';
import { addBypassChecker } from 'electron-compile';
addBypassChecker((filePath) => {
return filePath.indexOf(app.getAppPath()) === -1;
});
more infos here:
https://github.com/electron-userland/electron-compile/pull/199

Unable to resolve module 'expo-font.js'

I'm working with expo and snack and keep getting this error
Unable to resolve module 'module://expo-font.js' Evaluating module://expo-font.js Evaluating module://react-native-elements.js
...
I'm not importing any fonts and by tracing the path above, can see that it faults in the 'react-native-elements' module
Here are the dependencies in package.json
"react-native-elements": "0.19.1",
"react-navigation": "1.0.0-beta.27",
"react-native-animatable": "1.3.0",
"react-redux": "5.0.7",
"redux": "4.0.0",
"redux-logger": "3.0.6",
"redux-persist": "5.10.0",
"redux-persist/lib/storage": "5.10.0"
I also do not have access to the App.json file on snack until export
In the past changing the react-native-elements version to something lower hacked it but that doesn't seem to do the job anymore
I solved it by importing "expo-font"
In the Expo interface, I updated package.json I did this and it works.The key is to add "expo-font":"^1.0.0". Behind the scenes it resolves to expo-font#1.1.0.
"dependencies": {
"#babel/core": "^7.0.0",
"react-native-elements": "^1.0.0-beta7",
"expo-font": "^1.0.0",
"expo-asset": "~1.1.1",
"expo-file-system": "~1.1.0",
"expo-constants": "~1.1.0"
}

define entry point in legacy Grunt/Angular app for babel-pollyfill

I'm working with a legacy app we are slowly dragging forward to more modern libraries, etc. (I say this in advance to try to head off any "just upgrade to webpack/yarn/etc" answers. We're working on it, incrementally.)
Issue summary:
I have successfully included "grunt-babel": "^7.0.0", (I can see it working fine with a test let testBabel = 1 conversion). I also require "babel-polyfill": "^6.26.0"," to handle things like .includes() & Array function, which I have pulled in via my package.json "dependencies" (not "devDependencies", as I was instructed in the docs). My actual issue should be pretty simple: I have no understanding of the proper way to "load this via the entry file" for the set of libraries I am using.
Angular is v1.5
My Setup:
package.json
"devDependencies": {
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1",
"grunt": "^0.4.5",
"grunt-babel": "^7.0.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-sass": "^0.9.2",
"grunt-contrib-uglify": "^0.9.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-shell": "^2.1.0",
"load-grunt-tasks": "^3.5.2"
},
"dependencies": {
"babel-polyfill": "^6.26.0",
"d3-selection-multi": "~1.0.1",
"node-bourbon": "^1.2.3"
}
GruntFile.js
src: [
'./app/vinoEZ/javascripts/__header/jquery/jquery_number.js',
'./app/vinoEZ/javascripts/__header/jquery/hottie.js',
'./bower_components/localforage/dist/localforage.js',
'./bower_components/moment/min/moment.min.js',
'./app/vinoEZ/javascripts/__header/polyfill/entry.js',
'./app/vinoEZ/javascripts/__header/polyfill/eventsource.js',
'./bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js',
'./bower_components/smalot-bootstrap-datetimepicker/js/bootstrap-datetimepicker.js',
'./app/vinoEZ/javascripts/__header/underscore/underscore.js',
'./app/vinoEZ/javascripts/__header/myapp/base.js',
],
dest: './public/javascripts/myapp.head.min.js',
("myapp" is a substitute for our company name). The pollyfill/eventsource.js was existing, and so I have been working with pollyfill/entry.js as some of my experimentation - that may not be needed in the end.
In addition, we have our app.js file with all of our angular.module loading & directive stuff.
What I've tried:
I have tried adding require("babel-polyfill"); as the first line inside my module.exports = function(grunt) { - that seems to be ignored & I've been told that's wrong anyway
I have tried adding require("babel-polyfill"); and import "babel-polyfill"; inside that entry.js, which obviously isn't going to work and doesn't (syntax error as javascript doesn't understand)
I have tried add the same to the top of the angular app.js file but that just blows up my angular.
Really looking for a "write these words here", solve it for me answer, as I'm pretty sure it is a dead simple thing if you know what to type, but I'm at a loss.
TIA!
In the end, seems like a direct link is the easiest way to deal with this, especially as we are slowly upgrading the entire system.
CDN for anyone interested: https://cdn.polyfill.io/v2/docs/

Categories

Resources