DEV Community

Bo
Bo

Posted on

 

Vite: Module "path" has been externalized for browser compatibility

Problem

I am using Vite for some front end development, and when I used an external library which is using the "path" library, it throws this error:

Module "path" has been externalized for browser compatibility and cannot be accessed in client code.

Solution

Steps:

  1. Install "path-browserify":
$ npm install path-browserify
Enter fullscreen mode Exit fullscreen mode
  1. Add code to vite.config.ts:
import path from "path-browserify"

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      path: "path-browserify",
    },
  },
})
Enter fullscreen mode Exit fullscreen mode

Reference:

Top comments (3)

Collapse
 
ikbelkirasan profile image
Ikbel

Thank you!

Collapse
 
shishirraven profile image
Shishir Raven

Thanks for sharing Shishir Raven

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git