Closed ZeldOcarina closed 1 year ago
I just checked out your repro and I could see the log
If your issue is more specific, please make sure to create a repro for that.
Well I don't see it.. :( I am using npm, may that be a factor?
@ematipico I think you closed this a little too hastily.. :(
Even with npm
, I can see the log. It's essential to be able to replicate the issue. And I am using a mac like you.
Here's a StackBlitz repro, which definitely seems to be working.
@ZeldOcarina could you run npx astro info
and node --version
and share the output?
Of course!!
mattiarasulo@Host-006 astro-test % npx astro info
Astro version v2.10.12
Package manager npm
Platform darwin
Architecture arm64
Adapter Couldn't determine.
Integrations None or couldn't determine.
node --version
v18.15.0
Couldn't reproduce on windows or linux.
@ZeldOcarina it's possible that your terminal doesn't log for some reason. Why don't you try to use it by doing writing something into context.locals
, or something else.
Hi! All logs on standard routes etc. work properly. It's only the middleware that is not running at all, it's so weird.. May it be the M1 architecture?
Did you check if the middleware gets executed?
I did by hardcoding some locals and no locals are being passed down to the components etc..
Could you upload the dist folder somewhere, maybe in a branch.
That would at least rule out an astro bug from something about your environment.
Of course!
I've added the dist
folder under the same branch!
Builded the app and removed dist
from .gitignore
.
Thanks a lot for your help!
Ah, it's a static build. /dist
contains only html, css, and js.
It maybe worth adding an adapter (npm run astro add node
) to see if you get the issue in the final build (node dist/server/entry.mjs
) as well.
Ok done!
Interesting the middleware is called _empty-middleware.mjs
for some reason and it's actually empty!
https://github.com/ZeldOcarina/astro-middleware-bug/blob/main/dist/server/_empty-middleware.mjs
Ok, I see what you see now — not "Request received!".
Building again myself runs the middleware and logs to the console.
Not sure what the issue is. Best guess: you need to reinstall astro, or node. Run npm and other commands in a container if that doesn't work.
That's super weird.. I even tried with Bun and yarn..
I can confirm building in a Codespace container is working. I think still this should be investigated as it's a very weird behavior..
It's hard to investigate because as far as I can tell, the cause is is somewhere on your system.
I will try to open a remote M1 from a service I know and see if I can reproduce there.. it may be something that has to do with the ARM architecture..
I think the best course of action is creating a thread on discord, in the support channel, and chat with people there.
This seems to be an issue specific to someone machine/environment and unfortunately it's very hard to debug unless you do it yourself from the source code.
I have a M2 and I can't see this issue. Weird.
Ha I got it! Bug happens only if I clone the repo on my external SSD, won't happen on my main drive. Do you have an external disk you can try it on @ematipico?
I don't think there's much we can do. This is something related to your machine and environment, I can't look for an external hard drive 😅
Wow that is very strange! I have no idea what could be causing this problem when running on an external SSD. I agree that there's probably not much we can do, since it seems so environment specific... I tried searching through Vite, Rollup, Node issues but can't seem to find anything similar to this either.
There is this one issue: https://github.com/withastro/astro/issues/8164#issuecomment-1686046234.
Yeah so far only pnpm has always refused to work on the external SSD but I guess next time I will need to upgrade my Mac for that super expensive Apple storage instead of hacking together an NVME enclosure.. Thanks for your time, closing this for now!
same issue here
using mac mini m2 macOS 13.5.2(22G91)
node version v18.16.0
npm version 9.5.1
bun version 1.0.2
package.json :
"dependencies": {
"@astrojs/node": "^6.0.0",
"astro": "^3.1.1"
}
astro.config :
import { defineConfig } from 'astro/config';
import node from "@astrojs/node";
// https://astro.build/config
export default defineConfig({});
also tried node adapter
import { defineConfig } from 'astro/config';
import node from "@astrojs/node";
// https://astro.build/config
export default defineConfig({
output: "server",
adapter: node({
mode: "standalone"
})
});
and the result here (all test get same result)
i clone your astro-middleware-bug repo and get the same issue.
tried npm and bun both not working
realy wierd.
It really is. All the similar issues that I've seen so far are around project saved in file system that is different from the one where the OS is saved.
thanks for replying.
not working in my macbook pro M1. 😢
both my device doesn't have external drives, only the default built-in SSD.
so in my situation I don't know how to fix it.
maybe it's my personal setting error.
I will post my install detail tomorrow, or borrow a windows OS laptop and try again.
Could it be something related to the file system formatting? Maybe the error is in APFS or something like that?
Hello @ZeldOcarina. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro
will be closed if they have no activity within 3 days.
@lilnasy I think you do have a reproduction repo, let's not be too picky on that.. issue should not be closed..
So far I thought the linked repo would reproduce the issue on an external disk. But if someone is encountering the bug without it, there's probably another factor to consider.
Either way, I marked it as need repro because it's not an actionable issue, it's just going to sit here.
Ok thanks! :)
here is my install detail
npm create astro@latest
in folder terminal, and choose some setting.i get this dependencies in package.json
"dependencies": {
"astro": "^3.1.1"
}
add middleware.ts
inside src folder
type tree -I node_modules
and now my project look like this.
middleware.ts
export a onRequest functionimport { defineMiddleware } from "astro:middleware";
export const onRequest = defineMiddleware((context,next)=>{
console.log('middleware');
return next()
})
inside pages > index.astro
add console.log('page')
in frontmatter
run npm run dev
and go to http://localhost:4321/
now i got this issue
no 'middleware' but only 'page' in terminal log
seems like my onRequest didn't work 🫠.
did i miss any step or do anything wrong ??
I publish this folder to a github repo.
can anyone test if this is my personal issue.
thanks for reading this long post.
glad to get any advice.
@WinnieS0728 Pretty sure it's something about your (and ZeldOcarina's) system.
well i just create a new folder
and do
type git clone https://github.com/WinnieS0728/middleware-demo
cd ./middleware-demo
npm i
npm start
still got same issue.
but when i do these same step inside my github folder
and look what i got
now thing become SUPER WIERD 🤣
@WinnieS0728 Your investigation might be really helpful!
You have traditional chinese characters in the path in the first case where you encounter the issue.
Could you post a screenshot where you run the pwd
command in both cases?
And see if adding a chinese character to the GitHub
directory name breaks it as well.
pwd /Users/winnie.chang/Desktop/未命名檔案夾
result
pwd /Users/winnie.chang/Desktop/new folder
result
pwd /Users/winnie.chang/Documents/GitHub/未命名檔案夾
result
pwd /Users/winnie.chang/Documents/GitHub/new folder in github
result
pwd /Users/winnie.chang/Documents/GitHub
result
seems like only work direct inside github folder
english characters new folder in github folder pwd /Users/winnie.chang/Documents/GitHub/new folder in github
Could you remove spaces from this folder. Maybe /Users/winnie.chang/Documents/GitHub/new/
.
pwd /Users/winnie.chang/Documents/GitHub/new
result
pwd /Users/winnie.chang/Desktop/newFolder
result
i think you just resolve the issue 🥳.
@ZeldOcarina Is there a space in the full path in your project?
I can reproduce the issue on linux. middleware-demo -> "middleware demo" (with space)
so i think maybe is not personal issue ?
I don't know about detail, but I'm guessing is something like astro compiler detect folder name when build running env can't read space or chinese ?
@WinnieS0728 The fix in #8614 should work for chinese characters as well.
how about the space.
in my case i typed space almost 80% of my project if name have more than 1 words.
the chinese characters '未命名檔案夾' is means 'unnamed folder', and it's the default name when create a new folder in my mac.
i almost never use chinese characters in my projects.
Both spaces and non-english characters are fixed.
Thank you so so so much.
I search this issue almost a day around google, youtube and even Bing AI.
no one have same issue 🫠.
thanks for your help.
Thank you, you're the one who figured what the problem even is! Fixing is the easy part.
whoo whoo thanks a bunch @lilnasy @WinnieS0728 ! Yes there was some blank spaces in my OS. Sorry if the issue name was misleading, we made it!
What version of
astro
are you using?latest
Are you using an SSR adapter? If so, which one?
No
What package manager are you using?
npm
What operating system are you using?
Mac
What browser are you using?
Chrome
Describe the Bug
I have a tried a clean install of Astro with npm create astro@latest but I just cannot get my
middleware.ts
to run.I need to pass to components some context data and perform some global transformations on my response data but cannot do that.
What's the expected result?
Middleware running correctly. Not flagging willing to submit a pull request as I would not know where to start from.
Link to Minimal Reproducible Example
https://github.com/ZeldOcarina/astro-middleware-bug
Participation