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

fix(runtime): pass path instead of fileURL to isFilePathESM #15908

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/fetchModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function fetchModule(
throw err
}
const file = pathToFileURL(resolved.id).toString()
const type = isFilePathESM(file, server.config.packageCache)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When file is file:///C:/Users/green/foo.js, file:///C:/Users/green is passed to findNearestPackageData.

const pkg = findNearestPackageData(path.dirname(filePath), packageCache)

Then, file:\C:\Users\green\package.json is passed to tryStatSync.
const pkgPath = path.join(basedir, 'package.json')

fs.statSync('file:\C:\Users\green\package.json') throws Error: ENOENT: no such file or directory, stat 'C:\Users\green\file:C:Usersgreenpackage.json' error.

I didn't actually create a reproduction though.

const type = isFilePathESM(resolved.id, server.config.packageCache)
? 'module'
: 'commonjs'
return { externalize: file, type }
Expand Down