Skip to content
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

v3.3: compiler-sfc fails to resolve source when using path mapping #8140

Closed
cexbrayat opened this issue Apr 23, 2023 · 7 comments
Closed

v3.3: compiler-sfc fails to resolve source when using path mapping #8140

cexbrayat opened this issue Apr 23, 2023 · 7 comments

Comments

@cexbrayat
Copy link
Member

Vue version

3.3.0-beta.1

Link to minimal reproduction

https://stackblitz.com/edit/node-hrwual?file=repro/src/components/HelloWorld.vue

Steps to reproduce

Consider a component that uses an interface imported with path mapping (as the setup of a project generated with create-vue allows to do):

<script setup lang="ts">
import { User } from '@/User';
defineProps<{
  msg: string;
  user?: User;
}>();
</script>

What is expected?

The compiler should find the file, as if it was imported with:

import { User } from '../User';

What is actually happening?

When bumping from v3.2.47 to v3.3.0-beta.1, the compiler throws (with pnpm dev or pnpm build):

[@vue/compiler-sfc] Failed to resolve import source "@/User".

/home/projects/node-hrwual/repro/src/components/HelloWorld.vue
3  |  defineProps<{
4  |    msg: string;
5  |    user?: User;
   |           ^^^^
6  |  }>();
7  |  </script>
16:04:34 [vite] Internal server error: [@vue/compiler-sfc] Failed to resolve import source "@/User".

System Info

System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 4.89 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.volta/tools/image/node/16.17.0/bin/node
    Yarn: 1.22.17 - ~/.volta/tools/image/yarn/1.22.17/bin/yarn
    npm: 8.19.3 - ~/.volta/tools/image/npm/8.19.3/bin/npm
  Browsers:
    Chrome: 112.0.5615.137
    Firefox: 111.0.1
    Safari: 16.4
  npmPackages:
    vue: 3.3.0-beta.1 => 3.3.0-beta.1

Any additional comments?

No response

@sqal
Copy link
Contributor

sqal commented Apr 23, 2023

It seems that it does not work because you're using project references. If you add paths in your tsconfig.json it will work:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "files": [],
  "references": [
    {
      "path": "./tsconfig.node.json"
    },
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.vitest.json"
    }
  ]
}

@yyx990803
Copy link
Member

FYI this specific case should fallback to skipping runtime check without an error with latest main branch after 2d9f6f9 - that said project references are indeed not supported at the moment.

@gVguy
Copy link

gVguy commented May 24, 2023

I get this error (only during build) when importing a type with relative path eg:

'../types/myfile' ❌

when I use project root import, it resolves without errors

'@/types/myfile' ✅

I should note that this error arises when I import a file to use in defineProps<MyType>() since we can do that now which is awesome 🙂

I fixed it with alias import, but I think it should be fixed for relative imports too

@edison1105
Copy link
Member

@gVguy
relative import is already supported.
Could you provide a runnable minimal reproduction?

@simonbuerger
Copy link

I get this error (only during build) when importing a type with relative path eg:

'../types/myfile' ❌

when I use project root import, it resolves without errors

'@/types/myfile' ✅

I should note that this error arises when I import a file to use in defineProps<MyType>() since we can do that now which is awesome 🙂

I fixed it with alias import, but I think it should be fixed for relative imports too

@gVguy I am having the same issue, also only in an actual build and also only when importing a type to use in defineProps. Interestingly it only occurs on windows build agents, MacOS and linux are fine

@gVguy
Copy link

gVguy commented May 30, 2023

Interestingly it only occurs on windows build agents, MacOS

Can't confirm this, for me it occured on MacOS

d-koppenhagen added a commit to MelihAltintas/vue3-openlayers that referenced this issue Jun 12, 2023
@Dinert
Copy link

Dinert commented Aug 16, 2023

@gVguy Thank you, That helps me a lot.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants