Skip to content
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

🐛 BUG: fsonathan... Vite error when using fs in external files #2389

Closed
aFuzzyBear opened this issue Jan 14, 2022 · 9 comments
Closed

🐛 BUG: fsonathan... Vite error when using fs in external files #2389

aFuzzyBear opened this issue Jan 14, 2022 · 9 comments
Assignees

Comments

@aFuzzyBear
Copy link
Contributor

What version of astro are you using?

latest

What package manager are you using?

yarn

What operating system are you using?

wsl2; ubuntu 20.04, reproduced on stackblitz

Describe the Bug

Hi team,

I would like to report an issue raised in the support thread of Discord: https://discord.com/channels/830184174198718474/931342087725645834

Here I reported a vite error where when using nodes fs package in external *.js files, Vite throws an error, saying it cannot resolve dependencies,

This occurs with the following import statements

import fs from 'fs'
import fs from 'fs/promises'
import fs from 'node:fs'
import fs from 'node:fs/promises'

The present work around is to disable the import statement when launching the dev server and enabling them shortly after launch, it does throw in build also prohibiting the final build since Its one wee file using node.fs.writeFile()

Thanks to Muhymin for producing a reproduction,

Thank you guys for looking into this,

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-xs2jbp?file=src%2Fpages%2Findex.astro&on=stackblitz

@jonathantneal
Copy link
Contributor

Verified. If this is an intended limitation from Vite or Astro, we should document this.

@zadeviggers
Copy link
Contributor

I ran into this while trying to do some stuff with @astropub/codecs, if that's useful to anyone working on this.

@FredKSchott
Copy link
Member

I also just ran into this, in a file that was only ever run on the server and never meant for the client bundle. As @aFuzzyBear said, the current solution is to remove the import on dev server start and then add back after start, which feels weiiiiiiiird.

@FredKSchott
Copy link
Member

Ah, I believe that this is a Vite bug. fixed in vitejs/vite@4a05a6e but not yet in Astro.

@zadeviggers
Copy link
Contributor

Any ideas on when the fix might land in Astro?

@aFuzzyBear
Copy link
Contributor Author

Thanks Fred, for a while there I thought I was losing the plot there 😅

@FredKSchott
Copy link
Member

FredKSchott commented Feb 2, 2022

I had the same problem! @zadeviggers asap, you can track progress in #2424

@tony-sull
Copy link
Contributor

Fixed with the with the Vite upgrade in #2424 🥳

@aFuzzyBear
Copy link
Contributor Author

@tony-sull legend thank you...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants