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

[Resolve Method] extname is not function, at lookup function (vite) #124

Open
KumJungMin opened this issue May 17, 2024 · 1 comment
Open

Comments

@KumJungMin
Copy link

KumJungMin commented May 17, 2024

Issue

ErrorLog
(1) TypeError: extname is not a function
(2) Module "path" has been externalized for browser compatibility. Cannot access "path.${key}" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.

  • When i call lookup function in Vite ^5.2.0, extname undefined error occured!
// my project environment

"@vitejs/plugin-react": "^4.2.1",
"vite": "^5.2.0",
"mime-types": "^2.1.35",

스크린샷 2024-05-17 오전 9 29 41


  • Because Module "path" is incompatible.

스크린샷 2024-05-17 오전 9 33 23

스크린샷 2024-05-17 오전 9 33 08


How to Resolve

you can resolve this issue the following tip :)

(1) Install path-browserify. (link)

npm i path-browserify

(2) add path resolve option in vite.config.ts

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: [
      { find: '@', replacement: '/src' },
      { find: 'path', replacement: 'path-browserify' }, // this!!
    ],
  },
});
@KumJungMin KumJungMin changed the title extname is not function at lookup function (vite) [Resolve Method] extname is not function, at lookup function (vite) May 17, 2024
@romanown
Copy link

romanown commented Aug 6, 2024

i have error Could not read from file: /var/www/myproj/path-browserify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants