Description
Describe the bug
I am using repack 5.1.2 and creating a new project using react-strict-dom and respack. react-strict-dom
says to turn on packageExports in Metro (but of course I am not using Metro). So I set that option in Repack.getResolveOptions
However, that caused it to import the dom
version. I tracked it down to the byDependnecies:
key that was being returned by getResolveOptions
. I unset that key entirely and it fixed my issue.
See
repack/packages/repack/src/utils/getResolveOptions.ts
Lines 112 to 120 in 9793a50
/**
* We add `import` and `require` to conditionNames everytime
* because package imports are enabled at all times in metro
* and they need condition names to be defined.
*/
const byDependency = {
esm: { conditionNames: ['import'] },
commonjs: { conditionNames: ['require'] },
};
I don't know if omitting that when packageExports is on is correct, or if it needs to be more complicated (by including react-native
in there somewhere.
react-strict-dom's package.json:
"exports": {
".": {
"react-native": {
"types": "./dist/native/index.d.ts",
"default": "./dist/native/index.js"
},
"default": {
"types": "./dist/dom/index.d.ts",
"default": "./dist/dom/index.js"
}
},
"./babel-preset": "./babel/preset.js",
"./runtime": "./dist/dom/runtime.js",
"./package.json": "./package.json"
},
And here's a link to react-strict-dom's metro setup instructions: https://facebook.github.io/react-strict-dom/learn/setup/#metro-configuration
System Info
Sorry, I can't copy/paste between laptops.
- rnc/cli: 19.0.0
- react: 19.0.0
- react-native: 0.79.0
Re.Pack Version
5.1.2
Reproduction
I provided a lot of detail, but I don't have a repo. If you really need one I can try to make something to upload.
Steps to reproduce
- Create a new repack project
- add react-strict-dom
- turn on
enablePackageExports: true
import {html} from 'react-strict-dom';
and try to render a div or something. (It fails on import, so doesn't matter what you try to do with it)
Without turning on the packageExports flag, I was able to get rsd to work by using a deep import to the native directory. Once I turned it on, the deep import was not allowed and the shallow import also did not work. Once I cleared byDependency it started working again (with the the shallow import).