-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tsconfig paths support for serverMiddleware #339
Comments
@chanlito Unsure what is not working, why your import wouldn't work ? |
It works for module processed by webpack. |
Oh yeah you're right, I'll check in the coming days what can be done |
This is an issue for us as well : We use a monorepo where one of the packages is a nuxt typescript build , the rest is API, etc, etc - and we want to use the TS code + types directly in our code. in package/nuxt/tsconfig.json we have:
this works fine for API and IDE's but as soon as nuxt builds (webpack) it cannot find code that used @api/.... this can somehow be solved by using: https://github.com/TypeStrong/ts-loader#baseurl--paths-module-resolution But i have not found a way to extend the webpack config file that Nuxt uses (as the plugin needs to be in a 'resolve' field. I'm now needing to fully qualify all the paths (which is not good). UPDATE: Whilst typing i though i simply had not looked in the right place to make that plugin work: I've not updated the nuxt.config.js:
Now my builds works in IDE, TS Type checker and NUXT (Dev) - have not tried build yet. I'm aware that 'references' might work as well - but nuxt (or webpack) should respect the tsconfig.json file and parse it the best way possible. So if it was NUXT maintainer would add that to the @nuxt/typescript-build. |
@opgbaudouin About If you're really using such thing in your Nuxt app, you need to telle Webpack to add an alias so it correctly knows where to look. That's probably what does |
Yup - the cleanest way i found to do that between packages (in a monorepo) without resorting to d.ts generation, etc. This means TSC can literally use the original file in both typecheck AND transpiling.
Yup - but as the documentation has a paths field i was surprised that the one i added didn't work (whereas @ and ~ do work - which are in effect also just aliases to specific folder). it means the same file is idempotent. Considering NUXT does a lot of magic one might as well add this as it doesn't do much :) (did spent 2 hours on it ;) ). Can't wait for Nuxt 3 - hopefully with even better TS support and Vue 3 |
Thanks man! Typescript support for VueJS is a hell of a pain.😁 |
Anyone wanting to provide a PR against either the module or documentation to implement this feature request ? :) |
in my case, EDIT: This works "scripts": {
"dev": "node -r tsconfig-paths/register ./node_modules/@nuxt/typescript-runtime/bin/nuxt-ts.js"
} |
Based on the previous solutions, in my case this is the best way I found to allow tsconfig.json paths. First install tsconfig-paths-webpack-plugin:
Then be sure that the paths you want are defined in tsconfig.json:
Then you can use your defined paths as always in your typescript files:
Finally we need to update the
You can delete scripts starting with an underscore, those are just for documentation purposes. |
It feels like this should be supported out of the box. Are there any plans to support this in Nuxt 3? |
Is your feature request related to a problem? Please describe.
Right now, doing
import api from '@/serverMiddleware/api'
doesn't work.Describe the solution you'd like
It'd be nice to be able to import server modules this way.
Describe alternatives you've considered
There's current this https://www.npmjs.com/package/tsconfig-paths that could solve this issue.
The text was updated successfully, but these errors were encountered: