在调试 React 源代码时,我使用yarn link到我的项目,但得到错误

When debugging React source code, i use yarn link to my project,but get error

提问人:Pari 提问时间:11/8/2023 更新时间:11/8/2023 访问量:18

问:

最近,我想在本地调试React的源代码。我执行的主要操作如下: 1.从GitHub下载React源码 2.使用“yarn build react/index,react/jsx,react-dom/index,scheduler --type=NODE”在本地生成一个构建文件,就像这样,在这里输入镜像描述 进入oss-stable的/build/oss-stable/react和/build/oss-stable/react-dom目录,使用yarn link创建链接;

  1. 使用 react-create-app 创建了一个名为 a-react-demo 的项目,安装了依赖项
  2. 执行了 yarn link react 和 react-dom,并启动了项目,但遇到错误信息;
SyntaxError: /Users/zhujiaojiao/Documents/pari/other/react/packages/react/index.js: Support for the experimental syntax 'flow' isn't currently enabled (11:8):
   9 |
  10 | // Keep in sync with https://github.com/facebook/flow/blob/main/lib/react.js
> 11 | export type StatelessFunctionalComponent<P> =
     |        ^
  12 |   React$StatelessFunctionalComponent<P>;
  13 | export type ComponentType<-P> = React$ComponentType<P>;
  14 | export type AbstractComponent<

Add @babel/preset-flow (https://github.com/babel/babel/tree/main/packages/babel-preset-flow) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-flow (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-flow) to the 'plugins' section to enable parsing.
    at parser.next (<anonymous>)
    at normalizeFile.next (<anonymous>)
    at run.next (<anonymous>)
    at transform.next (<anonymous>)
ERROR in ../react/packages/react/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/zhujiaojiao/Documents/pari/other/react/packages/react/index.js: Support for the experimental syntax 'flow' isn't currently enabled (11:8):

   9 |
  10 | // Keep in sync with https://github.com/facebook/flow/blob/main/lib/react.js
> 11 | export type StatelessFunctionalComponent<P> =
     |        ^
  12 |   React$StatelessFunctionalComponent<P>;
  13 | export type ComponentType<-P> = React$ComponentType<P>;
  14 | export type AbstractComponent<

Add @babel/preset-flow (https://github.com/babel/babel/tree/main/packages/babel-preset-flow) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-flow (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-flow) to the 'plugins' section to enable parsing.
    at constructor (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:356:19)
    at Parser.raise (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:3223:19)
    at Parser.expectOnePlugin (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:3269:18)
    at Parser.isExportDefaultSpecifier (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:13855:16)
    at Parser.maybeParseExportDefaultSpecifier (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:13753:40)
    at Parser.parseExport (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:13685:29)
    at Parser.parseStatementContent (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:12720:27)
    at Parser.parseStatementLike (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:12593:17)
    at Parser.parseModuleItem (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:12570:17)
    at Parser.parseBlockOrModuleBlockBody (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:13194:36)
    at Parser.parseBlockBody (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:13187:10)
    at Parser.parseProgram (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:12469:10)
    at Parser.parseTopLevel (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:12459:25)
    at Parser.parse (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:14381:10)
    at parse (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:14401:26)
    at parser (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/core/lib/parser/index.js:41:34)
    at parser.next (<anonymous>)
    at normalizeFile (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/core/lib/transformation/normalize-file.js:64:37)
    at normalizeFile.next (<anonymous>)
    at run (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/core/lib/transformation/index.js:21:50)
    at run.next (<anonymous>)
    at transform (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/core/lib/transform.js:22:33)
    at transform.next (<anonymous>)
    at step (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:261:32)
    at /Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:273:13
    at async.call.result.err.err (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:223:11)
    at /Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:189:28
    at /Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/core/lib/gensync-utils/async.js:68:7
    at /Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:113:33
    at step (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:287:14)
    at /Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:273:13
    at async.call.result.err.err (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:223:11)

ERROR in ../react/packages/scheduler/src/forks/Scheduler.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/zhujiaojiao/Documents/pari/other/react/packages/scheduler/src/forks/Scheduler.js: Unexpected token, expected "from" (12:12)

  10 | /* eslint-disable no-var */
  11 |
> 12 | import type {PriorityLevel} from '../SchedulerPriorities';
     |             ^
  13 |
  14 | import {
  15 |   enableSchedulerDebugging,
    at constructor (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:356:19)
    at Parser.raise (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:3223:19)
    at Parser.unexpected (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:3253:16)
    at Parser.expectContextual (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:3567:12)
    at Parser.parseImportSpecifiersAndAfter (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:14158:10)
    at Parser.parseImport (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:14150:17)
    at Parser.parseStatementContent (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:12715:27)
    at Parser.parseStatementLike (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:12593:17)
    at Parser.parseModuleItem (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:12570:17)
    at Parser.parseBlockOrModuleBlockBody (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:13194:36)
    at Parser.parseBlockBody (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:13187:10)
    at Parser.parseProgram (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:12469:10)
    at Parser.parseTopLevel (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:12459:25)
    at Parser.parse (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:14381:10)
    at parse (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/parser/lib/index.js:14401:26)
    at parser (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/core/lib/parser/index.js:41:34)
    at parser.next (<anonymous>)
    at normalizeFile (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/core/lib/transformation/normalize-file.js:64:37)
    at normalizeFile.next (<anonymous>)
    at run (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/core/lib/transformation/index.js:21:50)
    at run.next (<anonymous>)
    at transform (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/@babel/core/lib/transform.js:22:33)
    at transform.next (<anonymous>)
    at step (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:261:32)
    at /Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:273:13
    at async.call.result.err.err (/Users/zhujiaojiao/Documents/pari/other/a-react-demo/node_modules/gensync/index.js:223:11)

webpack compiled with 2 errors

我是否链接到错误的文件作为错误消息标签“react/packages/react/index.js”而不是build/oss-stable/react

我更改了不同的文件,例如 oss-stable-semver 以使用 yarn 链接,但它仍然不起作用

JavaScript ReactJS 调试

评论


答: 暂无答案