Why this error happens:
dmc.MantineProvider wraps children in the @mantine/core context.
If your component is compiled with its own copy of Mantine (from node_modules), it’s asking a different context object.
React treats those contexts as completely separate — so it says MantineProvider was not found.
How to fix:
You need to make sure both dmc and your custom component resolve Mantine from the same place:
- In your custom component’s
package.json, mark Mantine as a peer dependency, not a regular dependency:
{
"peerDependencies": {
"@mantine/core": "^8.0.0",
"@mantine/hooks": "^8.0.0",
}
}
This way, it won’t bundle its own copy of Mantine.
- update
webpack.config.js to mark it as external as well:
const externals = {
react: {
commonjs: 'react',
commonjs2: 'react',
amd: 'react',
umd: 'react',
root: 'React',
},
'react-dom': {
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'react-dom',
umd: 'react-dom',
root: 'ReactDOM',
},
'@mantine/core': {
commonjs: '@mantine/core',
commonjs2: '@mantine/core',
amd: '@mantine/core',
umd: '@mantine/core',
},
'@mantine/hooks': {
commonjs: '@mantine/hooks',
commonjs2: '@mantine/hooks',
amd: '@mantine/hooks',
umd: '@mantine/hooks',
},
};
You will see the build size is much much smaller now too:
asset many_select.js 2.91 KiB [emitted] [minimized] (name: main)
Why this error happens:
dmc.MantineProviderwraps children in the@mantine/corecontext.If your component is compiled with its own copy of Mantine (from node_modules), it’s asking a different context object.
React treats those contexts as completely separate — so it says
MantineProviderwas not found.How to fix:
You need to make sure both dmc and your custom component resolve Mantine from the same place:
package.json, mark Mantine as a peer dependency, not a regular dependency:This way, it won’t bundle its own copy of Mantine.
webpack.config.jsto mark it as external as well:You will see the build size is much much smaller now too: