question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ViteJS doesn't seem to properly resolve symlinks

See original GitHub issue
  • Read the docs.
  • Make sure this is a Vite issue and not a framework-specific issue.
  • This is a concrete bug.

Describe the bug

ViteJs doesn’t properly resolve symlinks.

Reproduction

Repro repo: https://github.com/dbismut/preconstruct-repro After installing dependencies, please run yarn vite.

See comment here for hint at a solution. https://github.com/preconstruct/preconstruct/issues/378#issuecomment-789681043

Relevant bit from comment

We might notice here that the importer is in the dist directory - but it’s actually a linked file and thus it should be resolved to the real path (in the src directory). This is IMHO a problem with Vite’s resolver as this works correctly with most of the popular tools. This particular issue can be fixed by adjusting the body of this condition: https://github.com/vitejs/vite/blob/39820b96cec2c672e849e160b92b42c979b85285/packages/vite/src/node/plugins/resolve.ts#L348-L355 to:

resolved = fs.realpathSync(resolved)
return { id: resolved }

but I’m not super convinced that this is the appropriate place for the fix - the resolving logic in Vite is quite complex and has some layers. So it would really be best for them to assess at what level this should be fixed. It’s also worth noting that it might be worthwhile to use fs.realpathSync.native if it’s available in the given node version.

System Info

  • vite version: 2.0.5
  • Operating System: MacOS 11.2.2
  • Node version: 12.8.4
  • Package manager (npm/yarn/pnpm) and version: yarn 2.4.1

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.
[vite] Internal server error: Failed to resolve import "./data". Does the file exist?
  Plugin: vite:import-analysis
  File: /Users/david/repos/preconstruct-repro/packages/a/dist/myrepo-a.esm.js
  1  |  import { data } from "./data";
     |                        ^
  2  |  
  3  |  export function fn1() {
      at formatError (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:45829:46)
      at TransformContext.error (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:45825:19)
      at normalizeUrl (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:47321:26)
      at async TransformContext.transform (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:47450:57)
      at async Object.transform (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:46027:30)
      at async transformRequest (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:61631:29)
      at async /Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:61739:32
  vite:time 7ms   Users/david/repos/preconstruct-repro/packages/a/dist/myrepo-a.esm.js +22ms

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:6

github_iconTop GitHub Comments

3reactions
dbismutcommented, Mar 15, 2021

I just tried with Vite 2.1.0 and the issue persists.

2reactions
benmccanncommented, Oct 1, 2021

https://github.com/vitejs/vite/pull/4708 was just merged, which should fix this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Vite
When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project root.
Read more >
VSCode showing "cannot find module" TS error for .vue import ...
Seems Vetur looks in the VS Code workspace top-level folder for the tsconfig.json . My Vue app, with its tsconfig.json , is in...
Read more >
vite exports is not defined | The AI Search Engine You Control
This can also happen with the more common module.exports , but seems to not be ... from 'vite' import vue from '@vitejs/plugin-vue' import...
Read more >
David Bismut on Twitter: "@vite_js instantly builds the front-end ...
(we had to patch-package vite so that it properly resolves aliases paths) ... ViteJS doesn't seem to properly resolve symlinks · Issue #2405...
Read more >
Untitled
Have a yarn workspaces list command so people can get the resolved workspaces to ... In contrast, missing scripts without colons are properly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found