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

Vite import outside of package.json directory using tsconfig not working #10706

Closed
7 tasks done
hnviradiya opened this issue Oct 29, 2022 · 1 comment
Closed
7 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@hnviradiya
Copy link

Describe the bug

I am trying to import file from parent directory of package.json. So in tsconfig I have configured to bring import from parent directory of vue project.

But seems vite is unable to bring that file.

I have attached vue project, we can run that project and see the error for reproduction.

├── frontend/
│   ├── src/
│   │   ├── <frontend code>
│   ├── package.json
│   ├── tsconfig.json
├── shared/
│   ├── package.json
├── backend/
│   ├── src/
│   │   ├── <backend code>
│   ├── package.json
│   ├── tsconfig.json

Then in both the backend and frontend tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "~shared/*": ["../shared/*"]
    },
    "rootDirs": [
      "./src",
      "../shared"


    ]
  }
}

To allow access to the shared code e.g.:

import { Foo } from '~shared/foo';

vite import issue.zip

Reproduction

attached zip file in steps to reproduce

Steps to reproduce

Run npm install followed by npm run dev
vite import issue.zip

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700F
    Memory: 15.90 GB / 31.85 GB
  Binaries:
    Node: 16.15.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.674.0), Chromium (106.0.1370.34)
    Internet Explorer: 11.0.22621.1

Used Package Manager

npm

Logs

[plugin:vite:import-analysis] Failed to resolve import "~shared/test" from "src\App.vue". Does the file exist?
C:/Projects/GitLab/legal-disco-node/client/src/App.vue:4:22
2  |  import { RouterLink, RouterView } from "vue-router";
3  |  import HelloWorld from "./components/HelloWorld.vue";
4  |  import { value } from "~shared/test";
   |                         ^
5  |  const _sfc_main = /* @__PURE__ */ _defineComponent({
6  |    __name: "App",
    at formatError (file:///C:/Projects/GitLab/legal-disco-node/client/node_modules/vite/dist/node/chunks/dep-d29b4e33.js:41170:46)
    at TransformContext.error (file:///C:/Projects/GitLab/legal-disco-node/client/node_modules/vite/dist/node/chunks/dep-d29b4e33.js:41166:19)
    at normalizeUrl (file:///C:/Projects/GitLab/legal-disco-node/client/node_modules/vite/dist/node/chunks/dep-d29b4e33.js:38034:33)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async TransformContext.transform (file:///C:/Projects/GitLab/legal-disco-node/client/node_modules/vite/dist/node/chunks/dep-d29b4e33.js:38167:47)
    at async Object.transform (file:///C:/Projects/GitLab/legal-disco-node/client/node_modules/vite/dist/node/chunks/dep-d29b4e33.js:41419:30)
    at async loadAndTransform (file:///C:/Projects/GitLab/legal-disco-node/client/node_modules/vite/dist/node/ch

Validations

@sapphi-red
Copy link
Member

Vite doesn't support tsconfig's path: #6828

You could use resolve.alias to alias a path.
https://vitejs.dev/config/shared-options.html#resolve-alias

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2022
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Oct 29, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants