gpt4 book ai didi

reactjs - create-react-app 与 storybook 6.1.6 集成并且构建有错误

转载 作者:行者123 更新时间:2023-12-04 13:31:05 24 4
gpt4 key购买 nike

创建 react 应用程序版本

react: v17.0.1
react-scripts: v4.0.1
故事书版本
@storybook/react: v6.1.6
@storybook/addon-docs: v6.1.6
@storybook/core: v6.1.6
我可以运行 yarn start运行 react 应用程序并可以运行 start-storybook -p 9009 -s public开始故事书。
当涉及到构建 react 应用程序时,就会出现问题。往下看。
  • 当运行“yarn run build”时,它实际上运行 react-app-rewired start .
  • 它显示在下面
  • There might be a problem with the project dependency tree.
    It is likely not a bug in Create React App, but something you need to fix locally.

    The react-scripts package provided by Create React App requires a dependency:

    "babel-loader": "8.1.0"

    Don't try to install it manually: your package manager does it automatically.
    However, a different version of babel-loader was detected higher up in the tree:

    /Users/yejinlei/Documents/playground/personal/react-temp/node_modules/babel-loader (version: 8.2.1)

    Manually installing incompatible versions is known to cause hard-to-debug issues.

    If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
    That will permanently disable this message but you might encounter other issues.

    To fix the dependency tree, try following the steps below in the exact order:

    1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
    2. Delete node_modules in your project folder.
    3. Remove "babel-loader" from dependencies and/or devDependencies in the package.json file in your project folder.
    4. Run npm install or yarn, depending on the package manager you use.

    In most cases, this should be enough to fix the problem.
    If this has not helped, there are a few other things you can try:

    5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
    This may help because npm has known issues with package hoisting which may get resolved in future versions.

    6. Check if /Users/yejinlei/Documents/playground/personal/react-temp/node_modules/babel-loader is outside your project directory.
    For example, you might have accidentally installed something in your home folder.

    7. Try running npm ls babel-loader in your project folder.
    This will tell you which other package (apart from the expected react-scripts) installed babel-loader.

    If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
    That would permanently disable this preflight check in case you want to proceed anyway.

    P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
    我跑 npm ls babel-loader并见下图
    react-temp@0.1.0 /Users/yejinlei/Documents/playground/personal/react-temp
    ├─┬ @storybook/addon-docs@6.1.6
    │ └─┬ @storybook/core@6.1.6
    │ └── babel-loader@8.2.1 deduped
    └── babel-loader@8.2.1
  • 我按照说明运行 yarn add babel-loader@8.1.0 .完成后我得到以下信息:
  • react-temp@0.1.0 /Users/yejinlei/Documents/playground/personal/react-temp
    ├─┬ @storybook/addon-docs@6.1.6
    │ └─┬ @storybook/core@6.1.6
    │ └── babel-loader@8.2.1
    └── babel-loader@8.1.0
  • 然后运行 ​​yarn run build ,实际运行 react-app-rewired build并得到以下错误
  • playground/personal/react-temp/node_modules/react-scripts/scripts/build.js:19
    throw err;
    ^

    TypeError: aGeneratedCode.split is not a function
    at Function.SourceNode_fromStringWithSourceMap [as fromStringWithSourceMap] (playground/personal/react-temp/node_modules/source-map/lib/source-node.js:64:41)
    无法 build
    那么我的目标是代码 node_modules/source-map/lib/source-node.js并查看错误代码:
    /node_modules/source-map/lib/source-node.js

    64 var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);

    我运行并分析代码。 aGeneratedCode 将是“obejct”,所以我将代码更改如下。
        var remainingLines = typeof(aGeneratedCode) === "string" ? aGeneratedCode.split(REGEX_NEWLINE) : [];
    然后我现在可以运行 cra 应用程序和故事书的构建/启动。
    但为什么以及如何永久修复它?

    最佳答案

    我能够使用“分辨率”属性解决它
    ( https://classic.yarnpkg.com/en/docs/package-json/#toc-resolutions )

    "resolutions": {
    "babel-loader": "8.1.0"
    },

    关于reactjs - create-react-app 与 storybook 6.1.6 集成并且构建有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65031901/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com