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

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

Closed payalord closed 4 years ago

payalord commented 4 years ago

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)
ghost commented 4 years ago

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 4 years ago

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

Prozi commented 4 years ago

@payalord

payalord commented 4 years ago

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