question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File extension required in serverMiddleware

See original GitHub issue

Describe the bug File extension .ts is required in nuxt.config.ts serverMiddleware

To Reproduce Steps to reproduce the behavior:

  1. Create a nuxt typerscript project
  2. Create a file server/middleware.ts
  3. Set it to nuxt.config.ts like
{
serverMiddleware: [
    '~/server/middleware' // without extension
  ]
}
  1. Build with node ./node_modules/\@nuxt/typescript-runtime/bin/nuxt-ts.js build
  2. Start with node ./node_modules/\@nuxt/typescript-runtime/bin/nuxt-ts.js start
  3. See error

Error: Cannot find module ‘~/server/middleware’

Expected behavior This should work

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
kevinmarreccommented, Aug 29, 2019

Workarounds

Workaround N°1 Set @nuxt/typescript-build in modules instead of buildModules

Workaround N°2 (Recommended) Force ts extension in extensions array of configuration :

export default {
  extensions: ['ts']
}

Workaround N°3 Force ts extension in extensions array of configuration :

export default {
  extensions: ['ts']
}

Fix proposal

Use new CLI hooks (starting Nuxt 2.9.1), especially config one, to make nuxt-ts ensure that ts extension is registered, even when using nuxt-ts start.

0reactions
andywampircommented, Oct 30, 2019

It seems new version doesn’t works for me. I’m still getting error Cannot find module: '~/server/router'.

Versions

nuxt: 2.10.2 @nuxt/typescript-build: 0.3.2 @nuxt/typescript-runtime: 0.2.2 node: 12.13.0

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'.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found