Nuxt.js: Nuxt checks for serverMiddleware file existence in sources instead of built files

Created on 23 Sep 2018  路  14Comments  路  Source: nuxt/nuxt.js

Version

v2.0.0

Reproduction link

https://glitch.com/edit/#!/heady-cheque

Steps to reproduce

  1. Create a serverMiddleware file: $ touch ./src/api/index.js
  2. Add it to the config file:
{
    ...
    srcDir: 'src/',
    buildDir: 'dist',
    serverMiddleware: ['~/api/index'],
}
  1. Run $ nuxt build
  2. Deploy dist andnode_modules` directories to server
  3. Run $ nuxt start on the server (meaning without src/ directory)

What is expected ?

When Nuxt is started, it shouldn't check for a file existence in the sources, but check for a built one. We shouldn't need to deploy the sources into the server, but only the dependencies and the build directory (.nuxt or dist).

What is actually happening?

Nuxt will fail because it won't be able to resolve the middleware file since there isn't any src/ folder in the server.

This bug report is available on Nuxt community (#c7809)
bug-report documentation stale

All 14 comments

So, you are suggesting copying the middleware files to the dist as well?

and any loader registered in the nuxt.config.js build will not run for files in serverMiddleware
related to #3890 too

@manniL yes, if that's not already the case. All files necessary for runtime should ideally be present in the buildDir.

Thanks guys, I'm looking into this.

@IGassmann can you provide that glitch as a git repo or downloadable file? Or grant me access to download over at Glitch itself, of course.

Here it is: https://github.com/IGassmann/nuxt-servermiddleware-issue

Check out the commit history. The files that are currently in the repo mirror a server deployment. After cloning the repo, just run $ yarn start and you'll see the error I'm referencing.

@IGassmann thanks, saw it -- I'm pushing a fix soon cc @Atinux

Please check the Bug #3955 (Nuxt servermiddleware route /api is ignored when deployed or served on Firebase). It seems a related problem.....

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@galvez have you been able to fix this?

Is there any workaround?

Moving the serverMiddleware in the dist folder would lead to broken relative imports, which is somewhat hard to "prevent"/"avoid".

Instead, the documentation will include which files have to be present on the server soon:tm:.

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as 馃晲Pending will not be automatically marked as stale.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maicong picture maicong  路  3Comments

gary149 picture gary149  路  3Comments

surmon-china picture surmon-china  路  3Comments

vadimsg picture vadimsg  路  3Comments

mikekidder picture mikekidder  路  3Comments