Commit 847da2a
fix(codegen): read react-native.config.cjs so ESM projects are not silently skipped
readReactNativeConfig resolves the config with a single hardcoded extension:
const rnConfigFilePath = path.resolve(projectRoot, 'react-native.config.js');
A project whose package.json declares "type": "module" cannot use that
filename. Node parses .js as ESM there, and the require() two lines below
either throws (CommonJS body -- uncaught here, so codegen dies) or returns
{__esModule, default}, so rnConfig.dependencies is undefined and
findLibrariesFromReactNativeConfig returns [] without logging.
.cjs is the only extension that is both require()-able and legal in an ESM
package, and @react-native-community/cli already treats it as first-class via
searchPlacesForCJS. Codegen has its own resolver, does not use cosmiconfig, and
was never brought in line.
The result is that autolinking and codegen disagree about the same file:
autolinking reads the config and installs the pod, codegen does not and
generates nothing for that library, and the pod then fails to compile because
its Fabric component includes a header that was never generated.
Probe .cjs in addition to .js. .js is checked first, so projects that have one
resolve exactly as before.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 9b2a54e commit 847da2a
2 files changed
Lines changed: 58 additions & 3 deletions
File tree
- packages/react-native/scripts/codegen
- __tests__
- generate-artifacts-executor
Lines changed: 53 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
145 | 198 | | |
146 | 199 | | |
147 | 200 | | |
| |||
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
130 | 132 | | |
131 | 133 | | |
132 | | - | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
136 | | - | |
| 138 | + | |
137 | 139 | | |
138 | 140 | | |
139 | 141 | | |
| |||
0 commit comments