[reactjs] ‘반응 기본 시작’오류를 해결하는 방법

  1. 방금 node.js 및 cli를 설치했습니다.

    • 설치된 node.js
    • react-native-cli 설치

      npm -g react-native-cli
  2. 그리고 ‘새 프로젝트’를 만들었습니다.

    react-native init new_project
  3. 그리고 그 ‘new_project’디렉토리 안에서 메트로 번 들러가 잘 작동하는지보기에 지쳤습니다.

    react-native start
  4. 그러나 명령은 다음과 같은 오류를 주었고 메트로가 시작되지 않습니다. 이 오류를 수정할 단서가 있습니까? (Windows 10 OS를 사용하고 있습니다.)

    • 명령 : C:\projects\new_proj>react-native start

      오류 잘못된 정규식 : /(.\fixtures.|node_modules[]react[]dist[].|website\node_modules.|heapCapture\bundle.js|.\tests.)$/ : 종결되지 않은 문자 클래스입니다. 자세한 내용은 –verbose 플래그로 CLI를 실행하십시오. 구문 오류 : 잘못된 정규식 : /(.\fixtures.|node_modules[]react[]dist[].|website\node_modules.|heapCapture\bundle.js|.\tests.) $ / : 새 RegExp에서 종결되지 않은 문자 클래스 ( ) 블랙리스트 (D : \ projects \ new_proj \ node_modules \ metro-config \ src \ defaults \ blacklist.js : 34 : 10) at getBlacklistRE (D : \ projects \ new_proj \ node_modules \ react-native \ node_modules @ react-native -community \ cli \ build \ tools \ loadMetroConfig.js : 69 : 59) at getDefaultConfig (D : \ projects \ new_proj \ node_modules \ react-native \ node_modules @ react-native-community \ cli \ build \ tools \ loadMetroConfig.js) : 85 : 20) 부하시 (D :



답변

오늘 처음으로 비슷한 오류가 발생했습니다. 에 나타납니다 \node_modules\metro-config\src\defaults\blacklist.js. 변경해야하는 잘못된 정규식이 있습니다. 아래 sharedBlacklist에서 첫 번째 표현식을 다음 에서 변경했습니다 .

var sharedBlacklist = [
  /node_modules[/\\]react[/\\]dist[/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

에:

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];


답변

이것은 노드 v12.11.0이이 문제를 해결하는 두 가지 방법이있는 일반 위치를 처리하는 방식으로 인해 발생합니다.

방법 I

노드 v12.10.0으로 다운 그레이드하면 구문 분석 오류를 처리하는 올바른 방법이 적용됩니다.

방법 II

다음 위치에있는 파일을 변경하여 정규식을 올바르게 종료 할 수 있습니다.

\node_modules\metro-config\src\defaults\blacklist.js

에서:

var sharedBlacklist = [
  /node_modules[/\\]react[/\\]dist[/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

에:

 var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];


답변

[빠른 답변]

일부 NPM 및 Node 버전을 사용하는 Metro에 문제가 있습니다.

파일의 일부 코드를 변경하는 문제를 해결할 수 있습니다 \node_modules\metro-config\src\defaults\blacklist.js.

이 변수 검색 :

var sharedBlacklist = [
  /node_modules[/\\]react[/\\]dist[/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

다음으로 변경하십시오.

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

npm 설치 또는 원사 설치를 실행하는 경우 코드를 다시 변경해야합니다.


답변

두 가지 솔루션이 있습니다.

노드를 V12.10.0으로 다운 그레이드하거나 생성 할 모든 프로젝트에 대해이 파일을 수정할 수 있습니다.

node_modules / metro-config / src / defaults / blacklist.js
이것을 변경하십시오 :

var sharedBlacklist = [
  /node_modules[/\\]react[/\\]dist[/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

이에:

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];


답변

내 프로젝트에서 E : \ NodeJS \ ReactNativeApp \ ExpoTest \ node_modules \ metro-config \ src \ defaults \ blacklist.js를 변경 한 것과 동일한 문제가 발생했습니다.

…에서

var sharedBlacklist = [
  /node_modules[/\\]react[/\\]dist[/\\].*/,
  /website\/node_modules\/.*/,
 /heapCapture\/bundle\.js/,
 /.*\/__tests__\/.*/
];

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

이것은 나를 위해 완벽하게 작동했습니다.


답변

수정 사항이 있는 PR메트로 저장소 에 병합되었습니다 . 이제 다음 릴리스까지 기다려야합니다. 현재 가장 좋은 방법은 NodeJS로 다운 그레이드하는 것 v12.10.0입니다. 로 브랜든 지적, 아무것도 수정 node_modules/ISA 정말 나쁜 연습을하고 최종 해결책이 될 수 없습니다.


답변

내 프로젝트에 메트로 구성이 없습니다. 이제 어떻게합니까?

나는 꽤 이전 프로젝트에 더 있다는 것을 발견 한 metro-config에서 node_modules. 당신의 경우라면,

node_modules / metro-bundler / src / blacklist.js로 이동합니다.

그리고 다른 답변에서 언급 한 것과 동일한 단계를 수행하십시오.

바꾸다

var sharedBlacklist = [
    /node_modules[/\\]react[/\\]dist[/\\].*/,
    /website\/node_modules\/.*/,
    /heapCapture\/bundle\.js/,
    /.*\/__tests__\/.*/
];

var sharedBlacklist = [
    /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
    /website\/node_modules\/.*/,
    /heapCapture\/bundle\.js/,
    /.*\/__tests__\/.*/
];

추신 : 나는 두 프로젝트에서 같은 상황에 직면했기 때문에 그것을 공유하면 누군가에게 도움이 될 것이라고 생각했습니다.

편집하다

@beltrone의 의견에 따라 파일이 존재할 수도 있습니다.

node_modules \ metro \ src \ blacklist.js