nuxt-community/express-template

Cannot resolve '@' as nuxt does in regular nuxt project

Closed this issue · 4 comments

Starting from file api/index.js, where express server begins and nuxt serverMiddleware setup, all import paths with '@' cannot find that path/files to import. Here are the error in console:

ERROR  Cannot find module '@/api/routes/users'

What I need is for '@' to point to project root dir so i can include my custom js files from there, from any file that will be used in this server middleware including itself. My code of api/index.js:

import express from 'express'
import users from '@/api/routes/users'

const app = express()

// Import API Routes
app.use(users)

// Export the server middleware
module.exports = {
  path: '/api',
  handler: app
}
This question is available on Nuxt community (#c122)

This issue as been imported as question since it does not respect express-template issue template. Only bug reports and feature requests stays open to reduce maintainers workload.
If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically.
Your question is available at https://cmty.app/nuxt/express-template/issues/c122.

Prozi commented

you need either tsconfig or webpack config for resolving @ alias to another path

@Prozi thanks for trying to help me, we discussed this here in nuxt issues thread. And I provided my solution there.