Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error: "path.basename is not a function" #329

Open
vuejs/language-tools
#5304
@hatemhosny

Description

@hatemhosny

In the Vue REPL, any edits in the <template> would result in this error & with failure to autocomplete:

Image

The error is related to this line of code:
https://github.com/vuejs/language-tools/blob/7107d0ac24ccb292f9a876fba85dc835c4439788/packages/typescript-plugin/lib/requests/utils.ts#L43

export function getSelfComponentName(fileName: string) {
+	const baseName = path.basename(fileName);
	return capitalize(camelize(baseName.slice(0, baseName.lastIndexOf('.'))));
}

It seems that path-browserify polyfill is not working properly here.

Patching it to something like this fixed it:

export function getSelfComponentName(fileName: string) {
+	const baseName = fileName.split('/').pop() ?? '';
-	const baseName = path.basename(fileName);
	return capitalize(camelize(baseName.slice(0, baseName.lastIndexOf('.'))));
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions