Vue3/Vite: The requested module 'path' does not provide an export named 'path'


The requested module 'path' does not provide an export named 'path'

In creating a new Vue3 component library I was immediately presented with a SyntaxError: The requested module 'path' does not provide an export named 'path' exception when trying to build my project. In the package.json file there was a line that defined "type": "module". In order to fix the vite build error I changed the following snippet:

	// Didn't work
	const path = require('path');
	const { defineConfig } = require('vite');
	const vue = require('@vitejs/plugin-vue');
	// Works
	import { defineConfig } from 'vite'
	import vue from '@vitejs/plugin-vue'
	import path from 'path'

If you have this setup as a type of module module, you'll need to use import instead of require.

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.

joebdi
joebdi - Monday, August 21, 2023

Thanks dude 👍 , by the way u should mention when where are going to change that snippet i mean the fle