gatsby: Since adding a static asset, HMR fails and development mode stops working
Using Windows 10 x64 with Node 8, I encounter the issue below quite often while trying to change a file in development mode (gatsby develop
). I’m not sure about the cause, but the issue started when I added an asset to the project’s /static
directory.
I Your site is running at http://localhost:8000
I Your graphql debugger is running at http://localhost:8000/___graphql
info changed file at C:\Development\Projects\mvk-web\src\pages\gallery.jsx
WAIT Compiling... 00:16:17
error Plugin dev-404-page returned an error
Error: EPERM: operation not permitted, open 'C:\Development\Projects\mvk-web\.cache\dev-40 4-page.js'
- copy-file-sync.js:23 copyFileSync
[mvk-web]/[fs-extra]/lib/copy-sync/copy-file-sync.js:23:18
- copy-sync.js:43 Object.copySync
[mvk-web]/[fs-extra]/lib/copy-sync/copy-sync.js:43:5
- gatsby-node.js:34 _callee$
[mvk-web]/[gatsby]/dist/internal-plugins/dev-404-page/gatsby-node.js:34:18
- gatsby-node.js:51 Object.createPages
[mvk-web]/[gatsby]/dist/internal-plugins/dev-404-page/gatsby-node.js:51:18
- api-runner-node.js:104 runAPI
[mvk-web]/[gatsby]/dist/utils/api-runner-node.js:104:36
- api-runner-node.js:178
[mvk-web]/[gatsby]/dist/utils/api-runner-node.js:178:33
- map.js:27
[mvk-web]/[gatsby]/[async]/internal/map.js:27:9
- eachOfLimit.js:64 replenish
[mvk-web]/[gatsby]/[async]/internal/eachOfLimit.js:64:17
ERROR Failed to compile with 1 errors 00:16:18
error in ./.cache/dev-404-page.js
Module build failed: Error: ENOENT: no such file or directory, open 'C:\Development\Projects\mvk-web\.cache\dev-404-page.js'
@ ./.cache/sync-requires.js 11:53-123
info changed file at C:\Development\Projects\mvk-web\src\pages\gallery.jsx
WAIT Compiling... 00:16:22
error There was a problem reading the file: C:/Development/Projects/mvk-web/.cache/dev-404-page.js
Error: ENOENT: no such file or directory, open 'C:\Development\Projects\mvk-web\.cache\dev -404-page.js'
ERROR Failed to compile with 1 errors 00:16:23
error in ./.cache/dev-404-page.js
Module build failed: Error: ENOENT: no such file or directory, open 'C:\Development\Projects\mvk-web\.cache\dev-404-page.js'
@ ./.cache/sync-requires.js 11:53-123
Done in 94.08s.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 62 (41 by maintainers)
Commits related to this issue
- Remove i18n support Waiting for https://github.com/gatsbyjs/gatsby/issues/2819 to be resolved — committed to simonyiszk/mvk-web by kripod 7 years ago
- Fix copying "dev-404-page.js" to the cache folder on Windows (#3627) * Fix images disappearing from rendered markdown files Fixes #3608 * Revert invalid indentation changes * Fix copying "de... — committed to gatsbyjs/gatsby by kripod 6 years ago
- Fix copying "dev-404-page.js" to the cache folder on Windows (#3627) * Fix images disappearing from rendered markdown files Fixes #3608 * Revert invalid indentation changes * Fix copying "de... — committed to jastack/gatsby by kripod 6 years ago
- Plugin Library build fixes (#3906) * Support URLs that end in SemVer ranges (#3305) Fixes #3164. * page path defaults to '/' (#3325) * page path defaults to '/' * Add test * Use grayma... — committed to gatsbyjs/gatsby by gillkyle 6 years ago
EDIT - After using this for a while it still broke with the same EPERM issue so it looks like it reduces the chance of it happening but does not fix it.
I managed to reproduce this issue pretty reliably by doing the following
npm run develop
Result `error Plugin dev-404-page returned an error
Error: EPERM: operation not permitted, open ‘C:\Users\joe\Personal\jessiecouls onphotography.cache\dev-404-page.js’`
I played around with using the async version of fs.copy instead of the synchronous version and it appears to fix the issue. Frustratingly that means I don’t know the real cause or why this fixes the issue because I would expect fs.copy to run the same code as fs.copySync except in a non-blocking manner. It also means I can’t write any tests to ensure it is fixed and doesn’t regress in a future version. 😦
The fix is in the master branch of my fork at https://github.com/coulson84/gatsby if anyone else has been having this issue I would appreciate if you can pull and build this to see if it fixes things for you (N.B. I was getting a failed test from packages\gatsby-transformer-documentationjs\src_tests_\gatsby-node.js prior to making any change to my master branch).
Alternatively if you are feeling lazy you might be able to just copy the below directly in to node_modules/gatsby/dist/internal-plugins/dev-404-page/gatsby-node.js
I’m still seeing this issue on Windows:
Any ideas?
@gaearon just started to work on this actually 😃 Issue for this particular problem @ https://github.com/gatsbyjs/gatsby/issues/3094
@kripod
I can confirm the error has gone away, I do get one error but it doesn’t prevent gatsby from compiling which is: (apologies for the long compile)
You can now view gatsby-starter-default in the browser.
http://localhost:8000/
View GraphiQL, an in-browser IDE, to explore your site’s data and schema
http://localhost:8000/___graphql
Note that the development build is not optimized. To create a production build, use gatsby build
WAIT Compiling… 12:48:42 DONE Compiled successfully in 333ms 12:48:43 info changed file at S:\gatsbysowerbymark\src\pages\businesses\academydivers.md WAIT Compiling… 12:48:50
Accomodation Bars Alternative Therapy Massage Bakeries Barbers Beauticians Butchers Cafes Cards and Gifts Charity Shops Coffee Shops Chiropractors Cycle Shops Clothing Diy Shops Diving Tuition Dentists Delicatessens Eating Out Fashion Estate Agents Electrical Appliances Hairdressers Flower Shops Hair Salons Hardware Shops null Health null Insurance Brokers Key Cutters Jewellery Lettings Agents Manicurists Market Stalls Manufacturing null Pubs Opticians null Retailers Printers Sandwich Shops Shoe Repairers Sound and Vision null null Tyre Fitters Televisions Vacuum Repairs Vehicle Bodywork Vehicle Repairs ERROR Failed to compile with 1 errors 12:48:52 error in ./.cache/pages.json
Syntax Error: Unexpected end of JSON input at JSON.parse (<anonymous>)
@ ./.cache/root.js 26:13-36
WAIT Compiling… 12:48:52 DONE Compiled successfully in 457ms 12:48:52
admin@DESKTOP-HK27D9K MINGW64 /s/gatsbysowerbymark (master)
however i’m not sure if that is related
@kripod i would be willing to test it now if you could tell me what code to replace as it is currently making the development process no fun
I think I have fixed the issue for real, by changing the plugin loading order and awaiting
fs.copy
. I’ve tried to reproduce the bug with my fix in place, but couldn’t. 😊Does this happen on every Gatsby site for y’all? Or just certain ones? Could someone try installing various starters and testing this?
Also, it seems this is a windows-only issue but to double-check, has anyone seen this on Mac?
I am editing a blog post for the React website, and I see this error on every second edit:
It’s significantly disruptive to the workflow. Is this the same issue? How can I help debugging it?
@kripod Oddly enough, that didn’t work.
I managed to get it working again after editing and saving any non-JS file (e.g. markdown) while the server is still running. Although that comes with a caveat that it doesn’t really happen immediately. You gotta try doing it to one or two different files, until it gets kicked back up and running again.
This is really weird, and
we haven’t even scratched the surface on what’s actually causing it. /:On second thought, it’s most likely the weirdly-added spaces on the error logs that @kildareflare and others have been pointing out, but still…