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.

pre-bundle question when import path is absolute path

See original GitHub issue

Here is the example code:

// Area.tsx
import { areaList } from '@vant/area-data';
export default () => {
  console.log(areaList)
  return <div>this is arrea</div>
}

1.Pre-bundle will miss @vant/area-data:

// App.tsx
import Area from '/Users/3lang/Workspace/demo/vite-markdown/src/Area.tsx'

2.Pre-bundle as expected

// App.tsx
import Area from '/Users/3lang/Workspace/demo/vite-markdown/src/Area'

Vite resolved resource path resolvedId consistent with the rawid (user import code). Vite will be ignored as a virtual resource, and pre bunlde will not contain this Dep https://github.com/vitejs/vite/blob/cf03ecf3daf1f00c81de07b2429d38919ec920e7/packages/vite/src/node/optimizer/scan.ts#L511-L514

However, if it is a Vue (svelte) project, this will not happen

It will be dealt with internally: https://github.com/vitejs/vite/blob/cf03ecf3daf1f00c81de07b2429d38919ec920e7/packages/vite/src/node/optimizer/scan.ts#L268-L278

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
3lang3commented, Dec 13, 2021

The absolute path code was generated by the CLI tool, and then the pre bundle did not run as expected, which made me very confused. Therefore, I debugged the code and found the logic of resolvedid = = = rawid, so I created this issue.

Yes, I modify my cli code to adaptation vite with an alias

1reaction
bluwycommented, Dec 11, 2021

That might not be correct for this issue’s instance, but following #5494, I don’t think Vite has ever supported importing absolute paths, hence the quirk.

I also don’t quite understand the point of the vue/svelte code linked, I don’t think that affects this issue. That part of the code makes sure that Vite’s scanner doesn’t have conflicting var names when parsing vue/svelte files to JS.

Nonetheless, I think the correct way forward is to avoid absolute paths, and use aliases if possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relative path import fails, module not found, but absolute path ...
js not finding my command handler file using relative paths. VSCode resolves the path and suggests me the file, reading the directory with...
Read more >
How to change relative paths to absolute paths for imports
I have a React project set up using webpack, eslint, flow and jest. Here is a documentation of the places that require configurations...
Read more >
Dependency Pre-Bundling - Vite
When we do import { debounce } from 'lodash-es' , the browser fires off 600+ HTTP requests at the same time! Even though...
Read more >
FAQ • SvelteKit
Frequently asked questions about SvelteKit. ... const file = fileURLToPath (new URL ('package.json', import.meta. url ));. const json = readFileSync ( file ......
Read more >
Module Resolution - webpack
Since we already have the absolute path to the file, no further resolution is required. Relative paths. import '../src/file1'; import ...
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