Closed Himadu2000 closed 2 years ago
I'm having the same issue... 😢 Is there any suggested workaround yet?
Thanks @Himadu2000 for creating this issue. We are experiencing the same issue 😢. as we would like to use the gatsby-plugin-image
on our gatsby + nx app.
I'm having the same issue... 😢 Is there any suggested workaround yet?
@katterek You could temporary use <img src="" />
tag.
Such as,
Using url <img src="https://picsum.photos/200" />
Or as a query to image folder,
import { graphql, useStaticQuery } from "gatsby"
import React, { FC } from "react"
const Image: FC = () => {
// Edit image.png to your image name
// image.png is located in src/image folder
const data = useStaticQuery(graphql`
{
imageSharp(fluid: { originalName: { eq: "image.png" } }) {
fluid {
src
}
}
}
`)
return <img src={data.imageSharp.fluid.src} alt="Image" />
}
// You might need to install gatsby-plugin-sharp (This does come with default starter)
But there won't be optimizations done by gatsby-plugin-image. But they are a good temporary NX gatsby have lot of bugs so I don't think it will be soon fixed either
@dennislo Well lucky me my app only uses svg but some of other issues I created actually costing me time and Benjamins . And my release date for production app delay and my schedule getting haywire.
Is there any updates on the issue ? We would like to use gatsby + gatsby-plugin-image for our landing-web. The project is in early development. So we still debate if we should move away from nx for time being.
I have struggled with this too for several hours. Finally, I managed to get the plugin working by manually compiling plugin's gatsby-browser.js
; I followed these steps:
npm install @babel/cli
npx babel node_modules/gatsby-plugin-image/gatsby-browser.js --out-file node_modules/gatsby-plugin-image/gatsby-browser.js --presets=@babel/preset-react
This will compile gatsby-browser.js
and replace the original version within node_modules
; for reference, output result looks like this:
import React from "react";
import { LaterHydrator } from ".";
export function wrapRootElement({
element
}) {
return /*#__PURE__*/React.createElement(LaterHydrator, null, element);
}
As this change is done within node_modules
, then it's very fragile and a temporary solution. I strongly recommend you add the 2nd command to your package.json postinstall
script, as follows:
{
"scripts": {
...
"postinstall": "npx babel node_modules/gatsby-plugin-image/gatsby-browser.js --out-file node_modules/gatsby-plugin-image/gatsby-browser.js --presets=@babel/preset-react"
}
}
This way, if you reinstall your node_modules this command will run automatically.
@adrian-marcelo-gallardo Thank you, this runs well for now. Since you're installing @babel/cli, you do not need to run npx inside your postinstall script anymore
i got it working by also adding 'gatsby-plugin-image' to app's package.json. (not package.json at root level, but at project level).
So the app's project.json looks like:
{
"name": "gatsby-starter-default",
"private": true,
"description": "A simple starter to get up and develop quickly with Gatsby",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"gatsby": "*",
"gatsby-plugin-image": "*"
},
"devDependencies": {}
}
Closing this issue since we've moved Gatsby plugin to the labs repo. https://github.com/nrwl/nx-labs
Feel free to open it there.
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
Running
nx build app
provide following error (Failure Logs)Also note doing what was informed in log made no deference. Branch
Expected Behavior
Open the app without errors or warnings Is this a regression? No
Steps to Reproduce
Here's a Github repo And the following actions run
Steps,
Failure Logs
ERROR #98123 WEBPACK
Generating JavaScript bundles failed
C:\Website\Recreate-gatsby-image\node_modules\gatsby-plugin-image\gatsby-browser.js: Support for the experimental syntax 'jsx' isn't currently enabled (5:10):
3 | 4 | export function wrapRootElement({ element }) {
Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation. If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.
File: ....\node_modules\gatsby-plugin-image\gatsby-browser.js:5:9
Could not build "test". See errors above.
———————————————————————————————————————————————
Failed tasks:
Environment
Node : 14.17.0 OS : linux x64 yarn : 1.22.10
nx : Not Found @nrwl/angular : Not Found @nrwl/cli : 12.3.6 @nrwl/cypress : 12.3.6 @nrwl/devkit : 12.3.6 @nrwl/eslint-plugin-nx : 12.3.6 @nrwl/express : Not Found @nrwl/jest : 12.3.6 @nrwl/linter : 12.3.6 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : 12.3.6 @nrwl/react : 12.3.6 @nrwl/schematics : Not Found @nrwl/tao : 12.3.6 @nrwl/web : 12.3.6 @nrwl/workspace : 12.3.6 @nrwl/storybook : 12.3.6 @nrwl/gatsby : 12.3.6 typescript : 4.3.2