Reputation: 1414
I have some package on the node modules that have a package.json
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/{moduleName}/index.js",
"types": "./index.d.ts"
}
When vite trying to build it throw the error
[commonjs--resolver] Failed to resolve entry for package "/drone/src/node_modules/{module}/core/node_modules/@mui/material/LinearProgress". The package may have incorrect main/module/exports specified in its package.json: ENOENT: no such file or directory, lstat '/drone/src/node_modules/{module}/core/node_modules/@mui/material/LinearProgress/index.js' error during build:
My vite config is
import { defineConfig } from 'vite';
import RubyPlugin from 'vite-plugin-ruby';
export default defineConfig({
build: {
assetsInlineLimit: 2048,
rollupOptions: {
external: ['react', 'react-dom'],
output:{
globals: {
react: 'React',
'react-dom': 'ReactDom'
},
manualChunks(id) {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString();
}
}
}
}
},
plugins: [RubyPlugin()],
});
I find this Solution, but I can't remove it from the package.json
How can I solve this problem ?
Upvotes: 11
Views: 18850
Reputation: 195
If you are using the vite bundler, you can resolve it with an alias using https://vitejs.dev/config/shared-options.html#resolve-alias Ex:
resolve: {
alias: [
{
find: /@mui\/material/,
replacement: path.resolve(__dirname, 'node_modules', '@mui', 'material'),
},
],
},
Upvotes: 7