jest/preprocessor.js transforms packages/metro-config with sourceType: 'script' and leaves its import statements, so no Jest test in the repository can require @react-native/metro-config
Mantenedores costumam responder em até 2 dias
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- javascript, react-native
- Domínio
- build-system, testing
Direção de pesquisa
Read jest/preprocessor.js around the nodeFiles match and Babel options, then compare how those options transform packages/metro-config/src/index.flow.js. Run the reproducer linked in the issue to confirm the failing Jest require and check the output for each sourceType. Done means the test can require @react-native/metro-config while the matched files still receive the Node transform.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Description
A Jest test in this repository that requires @react-native/metro-config fails with SyntaxError: Cannot use import statement outside a module in packages/metro-config/src/index.flow.js.
packages/metro-config/ matches nodeFiles in jest/preprocessor.js, whose files go through metro-babel-register's Babel options with sourceType: 'script'. Those options leave the import and export statements of src/index.flow.js, which src/index.js requires, in place. Under sourceType: 'module' or 'unambiguous' the same options turn every one of them into a require call (step 3 below).
Expected: the test passes, and the files nodeFiles matches keep the Node transform.
Steps to reproduce
- Clone
react/react-nativeand runyarn installin it. - Clone the reproducer and run its script on that checkout:
It copies this test togit clone https://github.com/YevheniiKotyrlo/rn-jest-preprocessor-metro-config-repro ./rn-jest-preprocessor-metro-config-repro/jest-preprocessor/reproduce.sh react-nativepackages/react-native/src/private/__repro_metro_config__/__tests__/metro-config-from-source-test.js, runsyarn jeston it and removes it again:it('loads @react-native/metro-config from source', () => { const {getDefaultConfig} = require('@react-native/metro-config'); expect(typeof getDefaultConfig).toBe('function'); }); - The test fails with
SyntaxError: Cannot use import statement outside a moduleatpackages/metro-config/src/index.flow.js:13. The script then runs that file through the same Babel options under eachsourceType:metro-babel-register 0.88.0 sourceType: 'script' import/export statements left: 5, require calls: 1 sourceType: 'module' import/export statements left: 0, require calls: 3 sourceType: 'unambiguous' import/export statements left: 0, require calls: 3
The script exits 1 while the SyntaxError shows, 0 once the test passes, and 2 when a step fails or the test fails another way. It ends:
SUMMARY: defect shows on react/react-native e37dbfd9561: a Jest test that requires @react-native/metro-config fails with "SyntaxError: Cannot use import statement outside a module" in packages/metro-config/src/index.flow.js, whose import statements jest/preprocessor.js left in place
React Native Version
main (nightly) at e37dbfd95615b83d525bfaa99ddd3915c1bb2820
Affected Platforms
Build - Linux, Build - Windows
Output of npx @react-native-community/cli info
react/react-native e37dbfd9561 (2026-11-16), Node v26.12.1, Yarn 1.22.22, Jest 29.7.0, Windows_NT 10.0.26300 x64
react/react-native e37dbfd9561 (2026-11-16), Node v24.22.2, Yarn 1.22.22, Jest 29.7.0, Linux 6.18.58.1-microsoft-standard-WSL2 x64
Stacktrace or Logs
<react-native>\packages\metro-config\src\index.flow.js:13
import INTERNAL_CALLSITES_PATTERNS from './internalCallsites.json';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
MANDATORY Reproducer
https://github.com/YevheniiKotyrlo/rn-jest-preprocessor-metro-config-repro
Screenshots and Videos
No response
- Linguagem predominante
- C++
- Estrelas
- 127k
- Forks
- 25.5k
- Merge médio
- 3d 22h
- PRs com merge (30d)
- 235
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de react/react-native
-
Needs: Author Feedback Needs: Repro
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
react/react-native#60059 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
Needs: Triage :mag:
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
react/react-native#60000 ·
Mantenedores costumam responder em até 2 dias
-
`yarn test-ios` exits before building RNTester: `objc-test.sh` launches the WebSocket server script #59433 deletedTalvez já em andamento @lazerg assumiu há 4 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
react/react-native#59939 ·
Mantenedores costumam responder em até 2 dias
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primaryTalvez já em andamento @alleneubank assumiu há 6 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
react/react-native#59919 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
react/react-native#59722 ·
Mantenedores costumam responder em até 2 dias
Todas as issues de react/react-native
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
petercorke/robotics-toolbox-python#943 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
area:build bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
NatronGitHub/openfx-arena#71 ·
Mantenedores costumam responder em até 1 dia
-
upstream-watcher: Netflix/vmaf cf677baaa039 is not portedTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertaupstream-blocked
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
ROCm/FastFlowLM#1057 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
NatronGitHub/openfx-gmic#45 ·
Mantenedores costumam responder em até 1 dia