在react-create-app中babel加载器出现问题

35

问题

create-react-app 初始化的仓库中,安装的 babel-loader 版本比所需版本旧。

日志:

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.0.4"

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:

  C:\Users\user\node_modules\babel-loader (version: 8.0.2)

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

If 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 C:\Users\User\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 ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! reg@0.1.0 start: `react-scripts start`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the reg@0.1.0 start script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\User\AppData\Roaming\npm-cache\_logs\2018-12-13T18_22_47_802Z-debug.log

发生了什么之后

$ npx create-react-app reg && cd reg && npm start

我尝试过的方法

我尝试删除node_modules文件夹和package-lock.json文件,然后运行npm install

还安装了yarn并运行了yarn && yarn start

我已经重新创建了应用程序3次,并获得了相同的结果。

可能有用的信息

Node版本: 10.8.0
NPM版本: 6.5.0
create-react-app / react-scripts: 2.1.1
babel-loader: 8.0.4
全局软件包列表 (npm ls --depth=0 -g):

+-- create-react-app@2.1.1
+-- node-gyp@3.6.2
+-- npm@6.5.0
+-- yarn@1.12.3

package.json 文件:

{
  "name": "reg",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-scripts": "2.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

错误信息本身中有一系列修复指令,你尝试过它们了吗? - Agney
7
好的,我会尽力做到最好。请看“我尝试过的”部分。 - Paul Losev
第六步还是第七步? - Agney
@BoyWithSilverWings 从1到7 - Paul Losev
15个回答

0

对于我来说,通过在我的package.json文件中添加“解析”:{ “babel-loader”:“8.1.0” //所需版本 }解决了相同的问题。

  1. 删除node-modules、yarn.loack和package-lock.json
  2. yarn start
  3. 它完美地工作了

0

我在使用babel-loader@8.1.0时遇到了同样的错误,我从package.json中删除了引用,并从node_modules中删除了该模块,然后安装了“npm i babel-loader@8.1.0”,但是随后出现了@jest错误。

我从node_modules中删除了@jest模块,然后像解决babel-loader问题一样安装了所需的依赖版本。


0

我在使用以下命令创建应用项目后也遇到了问题:

create-react-app "project name"
create-react-app "project name" --use-npm
npx create-react-app. 

在所有情况下,结果都是在顶部指定的错误:

[项目依赖树可能存在问题。这很可能不是Create React App中的错误,而是您需要在本地修复的问题.......][...]

查看错误时,一行代码提供了一个小线索:

"/Users/john/node_modules/babel-loader (version: "7.1.5") -> was a version that creates conflict with above specified - version "babel-loader@8.0.6"

对我来说,解决方案是:通过我的文件夹跟踪此路径并删除node_modules文件夹,然后重新启动项目。


-1
/home/<username>/node_modules/babel-loader 目录下,只需更改 package.json 文件中的版本为“8.0.4”即可,在您的情况下也是如此。
对我来说起作用了。

-1

我曾经遇到过这个问题,只是添加了

"babel-loader": "8.0.4",

我在我的 package.json 文件的依赖项中添加了它,似乎解决了这个问题。


1
不要尝试手动安装它:您的软件包管理器会自动完成。 但是,在树的更高位置检测到了不同版本的babel-loader。 - 1nullpointer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接