我正在用React做一个项目,遇到了一个让我难住的问题。
当我运行yarn start时,我得到这个错误:
TypeError [ERR_INVALID_ARG_TYPE]: "path"参数必须是类型 字符串。接收类型未定义
我不知道为什么会这样。
我正在用React做一个项目,遇到了一个让我难住的问题。
当我运行yarn start时,我得到这个错误:
TypeError [ERR_INVALID_ARG_TYPE]: "path"参数必须是类型 字符串。接收类型未定义
我不知道为什么会这样。
当前回答
只需将反应脚本更新到最新版本。
yarn add react-scripts@latest
或者如果使用NPM
npm install react-scripts@latest
其他回答
去你的package.json 修改“react-scripts”:“3.x。X”到“react-scripts”:依赖项中的“^3.4.0” 重新安装react-scripts: npm I react-scripts 启动你的项目:npm Start
在我的例子中,我之前改变了文件夹路径,然后只有我在使用npm start时得到了这个错误。
因此,我将文件夹路径C:\Users\User\Documents\### Coding\todo-app更改为C:\Users\User\Documents\Coding\todo-app,然后它就工作了。
我认为问题是在文件夹名称中使用了这些特殊字符。
这与react无关,正如所指定的错误一样,undefined不被接受为path参数。确保没有将变量传递给path。恰巧未定义或为空的连接。 例如:
const {path} = require('path');
let arg = undefined;
let mypath = path.join(__dirname, arg);
// The same error would occur.
其他的解决方法对我都不起作用。
但是,将这个添加到我的包中。Json为我解决了这个问题:
"resolutions": {
"react-dev-utils": "10.0.0"
},
运行npm i react-dev-utils@10.0.0解决了我的问题。