File extension required in serverMiddleware
See original GitHub issueDescribe the bug File extension .ts is required in nuxt.config.ts serverMiddleware
To Reproduce Steps to reproduce the behavior:
- Create a nuxt typerscript project
- Create a file
server/middleware.ts
- Set it to nuxt.config.ts like
{
serverMiddleware: [
'~/server/middleware' // without extension
]
}
- Build with
node ./node_modules/\@nuxt/typescript-runtime/bin/nuxt-ts.js build
- Start with
node ./node_modules/\@nuxt/typescript-runtime/bin/nuxt-ts.js start
- See error
Error: Cannot find module ‘~/server/middleware’
Expected behavior This should work
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
The serverMiddleware Property - Nuxt
The serverMiddleware property. Define server-side middleware. Type: Array. Items: String or Object or Function. Nuxt internally creates a connect instance ...
Read more >The serverMiddleware Property - NuxtJS
Nuxt internally creates a connect instance that you can add your own custom middleware to. This allows us to register additional routes (typically...
Read more >Nuxt ServerMiddleware Returning HTML Doc - Stack Overflow
I am building out a webpage which needs to make a call to the Google Geocoder api. In order to hide the api...
Read more >Server Middleware | Vue Storefront 2
Every Vue Storefront application comes with the middleware.config.js file ... By default, Server Middleware runs as an extension to the Express server used ......
Read more >How to work with Server Middleware in Nuxt.js - YouTube
When you are know more about Middleware in Nuxt.js you will discovered you sometimes need server middleware in Nuxt.js, in this Video I...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Workarounds
Workaround N°1 Set
@nuxt/typescript-build
inmodules
instead ofbuildModules
Workaround N°2 (Recommended) Force
ts
extension inextensions
array of configuration :Workaround N°3 Force
ts
extension inextensions
array of configuration :Fix proposal
Use new CLI hooks (starting Nuxt 2.9.1), especially
config
one, to makenuxt-ts
ensure thatts
extension is registered, even when usingnuxt-ts start
.I got help in Discord server. Alias won’t be recognized, cause it’s runs outside webpack environment. So in my case i need to use
import router from '../server/router'
.