Subscribe on changes!

compiler-sfc failed to resolve external type imports under subdirectory

avatar
Jul 26th 2023

Vue version

3.3.4

Link to minimal reproduction

https://stackblitz.com/edit/stackblitz-starters-5bbywb?description=Starter%20project%20for%20Node.js,%20a%20JavaScript%20runtime%20built%20on%20Chrome%27s%20V8%20JavaScript%20engine&file=package.json,Test.vue,src%2Ftypes2.ts,src%2FTest.vue,src%2Findex.ts,package-lock.json&title=node.new%20Starter

Steps to reproduce

run

$ npm run dev

It works well.

then run

$ npm run dev:src

It fails with

Error: [@vue/compiler-sfc] Failed to resolve import source "./types2".

anonymous.vue
6  |  import type { Props } from './types2';
7  |  
8  |  defineProps<Props>();
   |              ^^^^^
9  |  </script>
10 |  
    at async ESMLoader.import (https://stackblitzstarters5bbywb-abfr.w-corp.staticblitz.com/blitz.bec01ace.js:35:1347715)
    at async i.loadESM (https://stackblitzstarters5bbywb-abfr.w-corp.staticblitz.com/blitz.bec01ace.js:35:352602)
    at async handleMainPromise (https://stackblitzstarters5bbywb-abfr.w-corp.staticblitz.com/blitz.bec01ace.js:35:1051734)
Failed running './src/index.ts'

What is expected?

compileScript should compile external relative type imports.

What is actually happening?

compile failed

System Info

System:
    OS: macOS 13.5
    CPU: (8) arm64 Apple M2
    Memory: 53.84 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
    npm: 9.5.0 - ~/.nvm/versions/node/v18.15.0/bin/npm
    pnpm: 8.6.2 - ~/.nvm/versions/node/v18.15.0/bin/pnpm
  Browsers:
    Chrome: 114.0.5735.248
    Safari: 16.6

Any additional comments?

Seems that const filename = joinPaths(scope.filename, '..', source) filename here lacks of relative path.

avatar
Jul 26th 2023

duplicate of https://github.com/vuejs/core/issues/8775 It will be fixed via https://github.com/vuejs/core/pull/8671/files, But https://github.com/vuejs/core/issues/8775 describes that it only happens on Windows, Could you test if #8775 will fix your problem as well?

avatar
Jul 27th 2023

Sorry my bad, I didn't pass filename on parse(code, {filename:''}), so compileScript cannot resolve the right file path. Thanks for reply :)