Javascript 类型错误 [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。启动反应应用程序时引发的接收类型未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/60234640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:21:24  来源:igfitidea点击:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined raised when starting react app

javascriptreactjsreduxvisual-studio-codeyarnpkg

提问by Fredrick Barrett

I'm working on a project in React and ran into a problem that has me stumped.

我正在 React 中处理一个项目,但遇到了一个让我难倒的问题。

Whenever I run yarn startI get this error:

每当我运行时,yarn start我都会收到此错误:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined

类型错误 [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。接收类型未定义

I have no idea why this is happening, if anyone has experienced this I would be grateful.

我不知道为什么会发生这种情况,如果有人遇到过这种情况,我将不胜感激。

回答by EngrEric

To fix this issue simply upgrade to "react-scripts": "^3.4.0"

要解决此问题,只需升级到 "react-scripts": "^3.4.0"

  1. Overwrite the existing "react-scripts": "^3.x.x"with"react-scripts": "^3.4.0"in your package.json
  2. Delete your node modules
  3. Run npm install or yarn install
  1. 覆盖现有的"react-scripts": "^3.x.x""react-scripts": "^3.4.0"你的package.json
  2. 删除您的节点模块
  3. 运行 npm install 或 yarn install

I hope it will fix faster you

我希望它会更快地修复你

回答by Fatema T. Zuhora

I've also faced this problem and figure out it by upgrading the react-scriptspackage from "react-scripts": "3.x.x"to "react-scripts": "^3.4.0"

我也遇到过这个问题,通过将react-scripts包从升级"react-scripts": "3.x.x""react-scripts": "^3.4.0"

  1. Delete node_modules\folder
  2. Delete package-lock.jsonfile
  3. Rewrite the package.jsonfile from "react-scripts": "3.x.x"to "react-scripts": "^3.4.0"
  4. Install node packages again npm i
  5. Now, start the project npm start
  1. 删除node_modules\文件夹
  2. 删除package-lock.json文件
  3. package.json文件改写"react-scripts": "3.x.x""react-scripts": "^3.4.0"
  4. 再次安装节点包 npm i
  5. 现在,开始项目 npm start

And it works!!

它有效!!

回答by Al DeLuca

We ejected from react-scriptsand so could not simply upgrade the package.json entry to fix this.

我们退出了react-scripts,所以不能简单地升级 package.json 条目来解决这个问题。

Instead, we did this: 1.) in a new directory, create a new project -> $> npx create-react-app foo-project2.) and then eject it -> cd ./foo-project && npm run eject3.) now copy the files from /foo-project/config into the config directory of our main app and fire up your dev server

相反,我们这样做了:1.) 在一个新目录中,创建一个新项目 -> $> npx create-react-app foo-project2.) 然后弹出它 -> cd ./foo-project && npm run eject3.) 现在将文件从 /foo-project/config 复制到我们主目录的 config 目录中应用程序并启动您的开发服务器

hope this helps others in a similar bind.

希望这可以帮助处于类似困境的其他人。

回答by Solijon Sharipov

I just had this issue after installing and removing some npm packages and spent almost 5 hours to figure out what was going on.

我在安装和删除一些 npm 包后才遇到这个问题,花了将近 5 个小时才弄清楚发生了什么。

What I did is basically copied my src/components in a different directory, then removed all the node modules and package-lock.json (if you are running your app in the Docker container, remove images and rebuild it just to be safe); then reset it to my last commit and then put back my src/components then ran npm i.

我所做的基本上是将我的 src/components 复制到不同的目录中,然后删除所有节点模块和 package-lock.json(如果您在 Docker 容器中运行您的应用程序,请删除图像并重建它以确保安全);然后将它重置为我的最后一次提交,然后放回我的 src/components 然后运行npm i.

I hope it helps.

我希望它有帮助。

回答by albert sh

Running npm i [email protected]solved my issue.

跑步npm i [email protected]解决了我的问题。

回答by edebo

  1. Go to you package.json

  2. Change "react-scripts": "3.x.x" to "react-scripts": "^3.4.0" in the dependencies

  3. Reinstall react-scripts: npm I react-scripts

  4. Start your project: npm start

  1. 去找你 package.json

  2. 将依赖项中的 "react-scripts": "3.xx" 更改为 "react-scripts": "^3.4.0"

  3. 重新安装反应脚本: npm I react-scripts

  4. 开始你的项目: npm start

回答by Geo Angelopoulos

If you have an ejectedcreate-react-app, I would suggest:

如果你有一个弹出create-react-app,我会建议:

  1. Create a new React app through create-react-app.
  2. Eject it through npm run ejector yarn eject.
  3. Install all the packages that are missing from the package.json.
  4. Copy your srcfolder assuming all your code is situated in this folder.
  5. Redo your changes on the configand scriptfolders, if needed.
  1. 通过create-react-app.
  2. 通过npm run eject或弹出它yarn eject
  3. 安装package.json.
  4. 假设您的所有代码都位于此文件夹中,请复制您的src文件夹。
  5. 如果需要,重做对configscript文件夹的更改。

Worked for me.

为我工作。

回答by jpz95

If you ejected and are curious, this changeon the CRA repo is what is causing the error.

如果您退出并感到好奇,则 CRA 存储库上的此更改是导致错误的原因。

To fix it, you need to apply their changes; namely, the last set of files:

要修复它,您需要应用他们的更改;即最后一组文件:

  • packages/react-scripts/config/paths.js
  • packages/react-scripts/config/webpack.config.js
  • packages/react-scripts/config/webpackDevServer.config.js
  • packages/react-scripts/package.json
  • packages/react-scripts/scripts/build.js
  • packages/react-scripts/scripts/start.js
  • 包/反应脚本/配置/paths.js
  • 包/反应脚本/配置/ webpack.config.js
  • 包/反应脚本/配置/webpackDevServer.config.js
  • 包/反应脚本/package.json
  • 包/反应脚本/脚本/build.js
  • 包/反应脚本/脚本/start.js

Personally, I think you should manually apply the changes because, unless you have been keeping up-to-date with all the changes, you could introduce another bug to your webpack bundle (because of a dependency mismatch or something).

就我个人而言,我认为您应该手动应用更改,因为除非您一直保持所有更改的最新状态,否则您可能会在 webpack 包中引入另一个错误(因为依赖项不匹配或其他原因)。

OR, you could do what Geo Angelopoulos suggested. It might take a while but at least your project would be in sync with the CRA repo (and get all their latest enhancements!).

或者,你可以按照 Geo Angelopoulos 的建议去做。这可能需要一段时间,但至少您的项目将与 CRA 存储库同步(并获得所有最新的增强功能!)。

回答by Binod Kafle

I tried various approach described above but none of them worked since I have ejectedmy css. Finally applying following steps helped:

我尝试了上面描述的各种方法,但自从我弹出了我的 css以来,它们都没有奏效。最后应用以下步骤有帮助:

  1. Upgradereact-scriptsfrom "react-scripts": "3.x.x"to "react-scripts": "^3.4.0"
  2. Downgrading react-dev-utilsform "react-dev-utils": "^10.x.x"to "react-dev-utils": "10.0.0"
  3. Delete node-modulesfolder and package-lock.json/yarn.lock
  4. Reinstall packages npm install/yarn install
  1. 升级react-scripts"react-scripts": "3.x.x""react-scripts": "^3.4.0"
  2. react-dev-utils表格降级"react-dev-utils": "^10.x.x""react-dev-utils": "10.0.0"
  3. 删除node-modules文件夹和package-lock.json/yarn.lock
  4. 重新安装软件包npm install/yarn install

回答by Rahul_Daksh

Follow the below steps. I also encountered the same problem.

请按照以下步骤操作。我也遇到了同样的问题。

  1. remove the whole node_modules folder.
  2. remove the package-lock.json file.
  3. run command npm install npm-installas shown in the image:

    showing the command to install npm

  4. Here we go.. npm start...wao

  1. 删除整个 node_modules 文件夹。
  2. 删除 package-lock.json 文件。
  3. npm install npm-install如镜像所显示,运行命令:

    显示安装 npm 的命令

  4. 来吧.. npm start..wao