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
.