DEV Community

BC
BC

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
 
kasir-barati profile image
Mohammad Jawad (Kasir) Barati

How about when we want to use node:path in our vite.config.ts? I am trying to use it but to no avail.

Collapse
 
ikbelkirasan profile image
Ikbel

Thank you!

Collapse
 
shishirraven profile image
Shishir Raven

Thanks for sharing Shishir Raven