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

限于喜欢 提交于 2020-02-21 08:18:12

问题


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

Whenever I run yarn start I get this error:

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

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


回答1:


To fix this issue simply upgrade to "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. and npm install or yarn install

i hope it will fix it faster you




回答2:


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

  1. Delete node_modules\ folder
  2. Delete package-lock.json file
  3. Rewrite the package.json file 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

And it works!!




回答3:


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

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.

I hope it helps.




回答4:


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

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

hope this helps others in a similar bind.



来源:https://stackoverflow.com/questions/60234640/typeerror-err-invalid-arg-type-the-path-argument-must-be-of-type-string-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!