I am currently working on a project that involves a module using full path exports instead of index files.
This project is divided into 2 NPM workspaces: one called core
and the other called examples
.
The challenge I am facing is avoiding long import paths like
@my-project/core/dist/plugins/Input
Although I have managed to configure Typscript to compile without requiring dist
in the path, Vite is unable to build it and throws an error stating it cannot find the necessary code:
Error: [vite]: Rollup failed to resolve import "@my-project/core/plugins/Input"
Typescript seems to be fine after some tweaking in the package.json file:
"typesVersions": {
"*": {
"*": [
"./dist/*"
]
}
},
I suspect there might be something in my Vite configuration causing this issue. Here is how my config looks:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig(() => {
return {
build: {
outDir: 'build',
},
plugins: [
react({
// Use React plugin in all *.jsx and *.tsx files
include: '**/*.{jsx,tsx}',
}),
],
server: {
port: 3000,
host: true,
},
preview: {
port: 4000,
},
};
});
I have tried various approaches to fix this issue and although I have made progress with TypeScript, I am still struggling to make Vite work properly. Any help or guidance would be greatly appreciated!