-
Notifications
You must be signed in to change notification settings - Fork 387
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
Use cross-env and esm together for gatsby-develop on windows powershell #28
Comments
This is not a solution, but one thing to note is that that it tries to find a file that doesnt exist It's got me curious now too 😆 |
yeah, the comments around similar issues mention that mac is more graceful at handling missing files than windows. I'm guessing there is some filename weirdness between windows/mac, but I'm still waiting for my old windows machine to boot/update |
yes! and if you take out that plugin, it just errors on the next plugin. I'm bettering |
Removing the plugins in their entirety makes it boot up to the Gatsby GraphQL errors 👀 |
Yeah that is noted above, if you get those graphql errors, it means it's working! So what about the plugins array is making it do that.. |
For reference running
with the
Results in the same error as using cross env, so I don't think the issue lies with the cross env package. |
Here is the whole stack trace from the error:
|
Not sure if it helps but I get a slightly longer stack trace
|
@Daniel-Griffiths It's the same stack-trace 🙂 - Wes just shortened it when he posted it here |
Woops 😆 |
Looks like this might be the issue, might need a PR to gatsby. |
@louisjrdev Yeah I noticed the same thing, the closest thing I have gotten this to work is to touch a .env and remove it later. But I know that doesnt meet the requirements 🤔 |
does putting it in a .env make it run? |
See also: gatsbyjs/gatsby#23705 |
@wesbos It changes the error
Looks the error shifts from gatbsy config and it looks like esm is not even enabled when using a |
I think it's less a "make ESM work with gatsby issue" than it is a "gatsby doesn't support esm fully yet". |
That error means @louisjrdev to be clear, this is using the |
@louisjrdev I am sure I got it working in the past by using Typescript but that's waaay out of scope for this 😅 |
Someone on twitter mentioned it works if you create an empty gatsby-config.js file in each plugin. So - why is gatsby looking for a config file in the plugin that doesn't exist? |
FYI you also get to the same point as @Daniel-Griffiths by replacing Potential gets you slightly further without having to use a |
That point isn't any further, I think that method doesn't expose the NODE_OPTIONS value to the child process and thus |
So if you run the following you can see (I think) that the child process does get the env variable, its just a problem with how handled after that: test.js
package.json
output
Apologies if it doesn't show what I think it shows |
Ok I got it working but the solution is a little nasty. Gimme a sec to write the solution... |
Oooh I have it working too |
So in the path
Go to line 40 And remove the code in that if statement so it looks like this: Then I used patch-package to persists the fix: https://www.npmjs.com/package/patch-package |
Ah! I was just looking at this: gatsbyjs/gatsby#17008 I wonder if Gatsby can be patched then? |
@wesbos Okay so i think I have solved this, without modifying any node modules. So in the gatsby-config.js make it:
Follow the instructions here: change the |
A bit hacky but it works, not sure if it does on mac / linux |
@louisjrdev thanks but that is removing all the ES Modules and just reverting it back to commonJS. So it gets rid of the problem, but also the feature :) |
Besides the above I can't find any other way to get this working. I think someone needs to submit a patch to Gatsby and find a real fix instead of deleting the problem 😆 patch-package has worked great for me in the past but I understand it's not the kind of thing you want to use on a course. |
Got it running based on @Daniel-Griffiths and this thread: gatsbyjs/gatsby#17008 If I crack open
with this:
It builds! So it's an issue with gatsby.. Perhaps they would fancy a PR |
Yeah, If I do the same it works on Windows so I can confirm that seems to be the fix to build it, and I tested on MacOS and it's still working there as well after I change it there. 👍 |
I will submit a PR to gatsby shortly, then we wait... 👀 |
Beat me to it 😆 |
its surprising that this isn't a more common issue, right? |
Yeah - very bizarre. It might have something to do with esm changing how paths reported? Not sure what it does under the hood. There were a few reports of it happening in gatsby, and none in esm though. |
@askkaz I guess most people end up sticking with commonjs as it's the default. 🤷♂️ I saw various articles and github threads trying to find a solution, but a lot of the fixes seem outdated and no longer work. |
Merged into gatsby. Thanks everyone! @Daniel-Griffiths shoot me an email and ill get you the $250 wesbos@gmail.com |
Awesome thanks @wesbos! 🙂 Will shoot you a email from [redacted] |
Here is a tricky one I can't get working. I'm using es modules for my
gatsby-config.js
andgatsby-node.js
files. Currently they only support common JS, so I am using theesm
package to use import/export syntax.The way we require
esm
is by settingNODE_OPTIONS="-r esm"
env variable, which requires the esm package first before runninggatsby develop
. To get it working on windows, we use the cross-env package.So the command looks like this:
"develop": "cross-env NODE_OPTIONS=\"-r esm\" gatsby develop",
Works great on a mac, but with windows powershell I get
Error 10123 We encountered an error while trying to load your site's gatsby-config. Please fix the error and try again.
. This only happens when there is a plugins array ingatsby-config.js
. Taking it out solves the problem.So to reproduce the error:
finished-files/gatsby
npm install
npm run develop
If you see GraphQL / Sanity errors, that is fine and means it worked. Don't worry about the site building, I just want to get past the above error.
Not acceptable solutions:
.env
file - that is introduced later in the courseIdeally
npm run develop
will work on all platforms, but I'm okay with anpm run develop:win
command.Things I've tried:
set NODE_OPTIONS="-r esm" && gatsby develop
- gatsby runs in a sub-process and it doesn't seem to transfer the variable downcross-env-shell
- it didn't work but not sure if I'm using it correctly.Happy to pay $250 USD to anyone who can get it running.
The text was updated successfully, but these errors were encountered: