Issue with @rsbuild/plugin-solid 1.2.0 #7680
-
|
Project built with this version of plugin fails to load in the browser with Uncaught ReferenceError: React is not defined. The problem seems to come from this - which ends up in the output of the build: return /*#__PURE__*/ React.createElement(Context.Provider, {
value: context,
__source: {
fileName: ".../rsbuild-solid/node_modules/.pnpm/@thisbeyond+solid-dnd@0.7.5_solid-js@1.9.13/node_modules/@thisbeyond/solid-dnd/dist/dev.jsx",
lineNumber: 716,
columnNumber: 10
},
__self: undefined
}, props.children);Seems that DragDropProvider from @thisbeyound/solid-dnd is compiled like a React element. This is not the case in v1.1.1. After further investigation, this part of code is introducing the problem api.modifyEnvironmentConfig((config) => {
const conditionNames = config.resolve.conditionNames ?? ['...'];
const useDevRuntime = dev ?? config.mode === 'development';
// Prefer Solid-specific exports while preserving user conditions or Rspack defaults.
config.resolve.conditionNames = [
...new Set([
'solid',
...(useDevRuntime ? ['development'] : []),
...conditionNames,
]),
];
});This always prepends 'solid' to resolve condition names, which causes React.createElement to appear in compiled output. OK, after more digging, I see that it was said that it's safe to add 'solid' to conditionNames always, but actually, for client side code only, it's not - it needs 'browser' also. vite-plugin-solid does this config.resolve.conditions = [
'solid',
...(replaceDev ? ['development'] : []),
...(isTestMode && !opts.isSsrTargetWebworker && !options.ssr ? ['browser'] : []),
...config.resolve.conditions,
];so if 'solid' is going to be added, 'browser' needs to be added too on condition. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Thanks for the report. I checked this, and the issue can happen, but it is not because Rspack is missing the For web targets, Rspack already includes The problem is that "exports": {
"solid": {
"development": "./dist/dev.jsx",
"import": "./dist/index.jsx"
},
"import": {
"default": "./dist/index.js"
}
}So after Adding Please make sure Babel also processes dependency pluginBabel({
include: /\.(?:jsx|tsx)$/,
}),
pluginSolid(), |
Beta Was this translation helpful? Give feedback.
Thanks for the report. I checked this, and the issue can happen, but it is not because Rspack is missing the
browsercondition.For web targets, Rspack already includes
browserin the defaultconditionNames(https://rspack.rs/config/resolve#resolveconditionnames), and@rsbuild/plugin-solidpreserves the default values via....The problem is that
@thisbeyond/solid-dnd@0.7.5has asolidexport before itsimportexport:So after
plugin-solidadds thesolidcondition, Rspack resolves this package to the.jsxentry. If Babel only processes a…