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

Can not use node modules in middleware.ts during build #527

Closed
1 task
donnikitos opened this issue Feb 4, 2025 · 2 comments
Closed
1 task

Can not use node modules in middleware.ts during build #527

donnikitos opened this issue Feb 4, 2025 · 2 comments

Comments

@donnikitos
Copy link

Astro Info

Astro                    v5.2.4
Node                     v22.12.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

Describe the Bug

When using any node:* module in the middleware the build process with configuration:

{
  output: 'server',
  adapter: vercel({
    edgeMiddleware: true,
  }),
}

fails with:

[build] Waiting for integration "@astrojs/vercel", hook "astro:build:done"...
✘ [ERROR] Could not resolve "node:path"

    dist/server/_astro-internal_middleware.mjs:2:24:
      2 │ import { dirname } from 'node:path';
        ╵                         ~~~~~~~~~~~

  The package "node:path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

Could not resolve "node:path"
  Location:
    dist/server/_astro-internal_middleware.mjs:2:24
  Stack trace:
    at failureErrorWithLog (/home/projects/github-7ls6muoe/node_modules/esbuild/lib/main.js:1466:15)
    at runOnEndCallbacks (/home/projects/github-7ls6muoe/node_modules/esbuild/lib/main.js:1306:49)
    at buildOrContextContinue/< (/home/projects/github-7ls6muoe/node_modules/esbuild/lib/main.js:960:16)
    at handleIncomingPacket (/home/projects/github-7ls6muoe/node_modules/esbuild/lib/main.js:667:20)
    at emit (node:events:30:10899)
    at readableAddChunk (node:internal/streams/readable:225:3393)
    at onStreamRead (node:internal/stream_base_commons:211:2596)
    at _0x12b09d/< (https://github7ls6muoe-103g.w-corp-staticblitz.com/blitz.d20a0a75.js:40:514366)
    at _0x520d6d (https://github7ls6muoe-103g.w-corp-staticblitz.com/blitz.d20a0a75.js:40:201442)
    at _0x2f86bf (https://github7ls6muoe-103g.w-corp-staticblitz.com/blitz.d20a0a75.js:40:510963)
    at _0x5a9943 (https://github7ls6muoe-103g.w-corp-staticblitz.com/blitz.d20a0a75.js:40:514536)

During development everything works as expected.
Not sure if this is related to Vercels adapter or not as the process fails after [build] Waiting for integration "@astrojs/vercel", hook "astro:build:done"....

What's the expected result?

Build completion

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-7ls6muoe

Participation

  • I am willing to submit a pull request for this issue.
@ematipico
Copy link
Member

You're using the Vercel edge runtime, which has a different runtime: https://vercel.com/docs/functions/runtimes/edge-runtime

@donnikitos
Copy link
Author

OMG, that's it!
Never mind then. Thanks for pointing it out.

But it would be pretty handy to receive a notice during development too!

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

2 participants