pre-bundle question when import path is absolute path
See original GitHub issueHere 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:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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.