如何从默认的“rails new app”和“npx create-react-app”修复这些依赖问题?

Posted

技术标签:

【中文标题】如何从默认的“rails new app”和“npx create-react-app”修复这些依赖问题?【英文标题】:How do I fix these dependency issues from default "rails new app" and "npx create-react-app"? 【发布时间】:2020-02-21 21:39:43 【问题描述】:

我正在尝试使用默认设置创建一个新的 Rails 应用程序,并使用 npx create-react-app 为客户端创建一个文件夹。出于某种原因,一切都安装得很好,但我无法弄清楚为什么 webpack 版本号与我的默认值不匹配。每次我在客户端文件夹中 cd 并尝试纱线启动时,我都会收到此错误。

为了澄清,我的 npx create-react-app 客户端是在 myapp 文件夹中运行的...所以 react 当前位于.../Users/JohnnyBrown/Desktop/myapp/client

我不明白我是如何在默认命令之外遇到 webpack 版本问题...

在终端中使用 -v 时,我的所有版本号如下:

rails 6.0 版, 纱线 v - 1.17.0, npm -v 6.9.0, 节点-v 10.13.0 webpack -v 4.34.0

我已经尝试过它提供的选项,这些选项正在删除树上的东西,但这没有奏效.. 至少我什至无法让 .env 文件工作,也许我没有把它在正确的地方?任何见解将不胜感激..

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:

  "webpack": "4.41.0"

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

  /Users/JohnnyBrown/Desktop/myapp/node_modules/webpack (version: 4.41.2) 

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 "webpack" 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/JohnnyBrown/Desktop/myapp/node_modules/webpack is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

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

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.```

【问题讨论】:

【参考方案1】:

检查您的项目文件夹之外是否没有 node_modules.. 您必须删除它并再次运行“npm start”

【讨论】:

以上是关于如何从默认的“rails new app”和“npx create-react-app”修复这些依赖问题?的主要内容,如果未能解决你的问题,请参考以下文章

如何更改 matplotlib - spyder 中的默认绘图颜色? [复制]

如何从存储在.csv中的熊猫数据框中读取np矩阵?

如何在 matplotlib 图中设置默认缩放?

python使用numpy的np.power函数计算numpy数组中每个数值的指定幂次(例如平方立方)np.power函数默认返回整数格式np.float_power函数默认返回浮点数

如何使用 Pandas 从 DataFrame 或 np.array 中的列条目创建字典

python 中 np.arange()的使用