nuxt-community / express-template

Starter template for Nuxt 2 with Express.
https://codesandbox.io/s/github/nuxt-community/express-template
1.25k stars 239 forks source link

How can I use absolute import in express api backend? #196

Closed ZombieChibiXD closed 3 years ago

ZombieChibiXD commented 3 years ago

In nuxt .vue files, I can just use '@/path/to/component', but for some reason the same thing don't work on the express.js files..

SWDevStudio commented 3 years ago

I have the same problem, I can not understand how to set up the work of alias for Express files

atinux commented 3 years ago

Hi, at the moment aliases are not supported in server middleware, you have to use relative path.

kotvasili commented 3 years ago
import moduleAlias from "module-alias";

moduleAlias.addAliases({
  "@": path.join(__dirname, "/../"),
});

@ZombieChibiXD This is how I solved it inside serverMiddleware folder