Vue 3.3 unable to resolve external package types if external file contains relative import and extension
Vue version
3.3.2
Link to minimal reproduction
https://github.com/kalvenschraut/vue-unresolved-types-build-failure
Steps to reproduce
See README in the repo.
What is expected?
Build not to fail and type to be resolve
What is actually happening?
I think the problem is that vue is trying to do a relative resolve of an import that is inside of an external package.
While this could work, would have to fix resolveExt
to handle the various scenarios, I think the more ideal direction is to allow typescript resolve these relative imports if there are not within your own package here.
https://github.com/vuejs/core/blob/a374d7e6ed973cde7fae36ee82618cf46a8ba68a/packages/compiler-sfc/src/script/resolveType.ts#L746
Not sure how feasible that direction is. Only thing I can think of it having to know where the project root is and compare the source.filename with that before determining your direction. Maybe by using process.cwd()?
Otherwise, I would just strip off any extension and try the various ones it already is doing. The .js extension will resolve to the actual built file without the types which would be bad. If allow .ts extension still needs to be stripped since likely looking for .d.ts if its inside an external package due to the files likely being built by some tool.
System Info
System:
OS: Linux 5.15 Gentoo Linux
CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
Memory: 19.12 GB / 26.78 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 18.12.1 - /usr/bin/node
Yarn: 3.3.0 - /usr/bin/yarn
npm: 8.19.2 - /usr/bin/npm
Watchman: 2023.01.16.00 - /usr/bin/watchman
Browsers:
Firefox: 102.7.0esr
npmPackages:
vue: 3.3.2 => 3.3.2
Any additional comments?
Made a separate issue from #8326 as that one is about making the build not fail, this one is about making sure the type is resolved.