【问题标题】:Create-React-App: ESlint error while deployment on local machineCreate-React-App:在本地机器上部署时出现 ESlint 错误
【发布时间】:2020-05-24 06:03:04
【问题描述】:

我正在使用 create-react-app (React v16.12.0)。在 mac 上运行 'npm start' 时出现以下错误。

[1] There might be a problem with the project dependency tree.
[1] It is likely not a bug in Create React App, but something you need to fix locally.
[1]
[1] The react-scripts package provided by Create React App requires a dependency:
[1]
[1]   "eslint": "^6.6.0"
[1]
[1] Don't try to install it manually: your package manager does it automatically.
[1] However, a different version of eslint was detected higher up in the tree:
[1]
[1]   /Users/abz/node_modules/eslint (version: 6.5.1)
[1]
[1] Manually installing incompatible versions is known to cause hard-to-debug issues.
[1]
[1] If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
[1] That will permanently disable this message but you might encounter other issues.
[1]
[1] To fix the dependency tree, try following the steps below in the exact order:
[1]
[1]   1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
[1]   2. Delete node_modules in your project folder.
[1]   3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.
[1]   4. Run npm install or yarn, depending on the package manager you use.
[1]
[1] In most cases, this should be enough to fix the problem.
[1] If this has not helped, there are a few other things you can try:
[1]
[1]   5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
[1]      This may help because npm has known issues with package hoisting which may get resolved in future versions.
[1]
[1]   6. Check if /Users/abz/node_modules/eslint is outside your project directory.
[1]      For example, you might have accidentally installed something in your home folder.
[1]
[1]   7. Try running npm ls eslint in your project folder.
[1]      This will tell you which other package (apart from the expected react-scripts) installed eslint.
[1]
[1] If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
[1] That would permanently disable this preflight check in case you want to proceed anyway.
[1]
[1] P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
[1]
[1] react-scripts start exited with code 1

我搜索了一下发现

  1. 许多人建议的以下解决方案

    • users/abz/node_modules/文件夹中删除eslint and babel-eslint
    • 从本地项目中删除package.json-lock, node_modules
    • 运行npm installnpm start

    我试过了,这个解决方案对我不起作用。

  2. 这个问题可以通过使用来缓解

    adding an `.env file` in root folder with statement `SKIP_PREFLIGHT_CHECK=true` 
    

    但是,这不是解决这个问题的办法。

有什么帮助吗?

【问题讨论】:

    标签: reactjs dependencies create-react-app eslint


    【解决方案1】:

    发生这种情况是因为在父级别安装了具有不同版本的依赖项。在您的情况下,它是/Users/abz/node_modules/eslint。只需从 root 运行此命令

    rm -rf node_modules/eslint
    

    这应该可以解决您的问题。

    【讨论】:

    • 是的。谢谢阿努杰。删除 eslint 后,它要求几个类似的版本不匹配。我使用上面相同的命令删除了所有内容。
    • 运行命令后,即使应用程序运行良好,也有警告说:“无法加载在'baseconfig'中声明的插件'import',找不到模块'eslint'”。并将 npm 更新到最新版本 [npm install -g npm@latest] 然后 npm start 运行良好。 Reference
    • 非常感谢这对我有用。但我的另一个问题是,如果我删除这个文件夹,当我运行 npx eslint . 时,eslint 是否会工作
    【解决方案2】:

    按照 Anuj shah 和 SHAHBAZ 的回复:

    1. rm -rf node_modules/eslint
    2. npm install -g npm@latest

    或者只是做npm i -S fsevents

    解决了这个问题。

    但是每当我安装另一个软件包时,我都必须一次又一次地执行上述步骤。这太令人沮丧了...

    有人对此有更好的解决方案吗?

    【讨论】:

      【解决方案3】:

      只要运行:

      npm uninstall eslint
      

      错误将消失。

      注意:npm uninstall -g eslint 在我的情况下不起作用

      【讨论】:

        【解决方案4】:

        在我的 C 驱动器的根目录中,我找到并删除了 node_modules 文件夹,因为它被指出为包含 eslint-lint 的文件夹,与我的项目中的文件夹冲突。就是这么神奇!

        【讨论】:

          【解决方案5】:

          我已完成以下步骤并解决了问题...

          1. 删除node_modules、package-lock.json / yarn.lock
          2. 将 "eslint": "^6.6.0" 添加到您的 devDependencies
          3. 运行 npm install / yarn
          4. 运行 eslint --init 命令
          5. 安装你需要的 eslint 插件

          【讨论】:

            【解决方案6】:

            您正在使用多个不同版本的 react-script。更新它们以使用相同的版本应该可以解决您的问题

            【讨论】:

              【解决方案7】:

              快跑

              npm install --save --save-exact react-scripts@4.0.3
              

              yarn add --exact react-scripts@4.0.3
              

              https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md

              【讨论】:

                猜你喜欢
                • 2018-12-25
                • 2019-03-06
                • 2019-05-07
                • 2023-03-02
                • 2021-03-06
                • 2020-09-02
                • 2020-08-18
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多