问题
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"
- Overwrite the existing
"react-scripts": "^3.x.x"
with"react-scripts": "^3.4.0"
in your package.json - Delete your node modules
- 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"
- Delete
node_modules\
folder - Delete
package-lock.json
file - Rewrite the
package.json
file from"react-scripts": "3.x.x"
to"react-scripts": "^3.4.0"
- Install node packages again
npm i
- 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