我正在用React做一个项目,遇到了一个让我难住的问题。
当我运行yarn start时,我得到这个错误:
TypeError [ERR_INVALID_ARG_TYPE]: "path"参数必须是类型 字符串。接收类型未定义
我不知道为什么会这样。
我正在用React做一个项目,遇到了一个让我难住的问题。
当我运行yarn start时,我得到这个错误:
TypeError [ERR_INVALID_ARG_TYPE]: "path"参数必须是类型 字符串。接收类型未定义
我不知道为什么会这样。
当前回答
这与react无关,正如所指定的错误一样,undefined不被接受为path参数。确保没有将变量传递给path。恰巧未定义或为空的连接。 例如:
const {path} = require('path');
let arg = undefined;
let mypath = path.join(__dirname, arg);
// The same error would occur.
其他回答
只需将反应脚本更新到最新版本。
yarn add react-scripts@latest
或者如果使用NPM
npm install react-scripts@latest
我在流水线上运行时也遇到了同样的问题。
对我来说,问题是我在docker容器中使用的节点版本为v10.0.0。
更新到v14.7.0为我解决了这个问题
只需要删除并重新安装反应脚本
删除 Yarn删除反应脚本 添加 Yarn添加反应脚本
然后rm -rf node_modules/ yarn。锁纱
记住不要经常更新react-scripts版本
如果您在package中添加了一个包。Json,然后你删除了它。记住要删除添加在/config/plugin.js或任何与该包相关的地方的任何配置。
这与react无关,正如所指定的错误一样,undefined不被接受为path参数。确保没有将变量传递给path。恰巧未定义或为空的连接。 例如:
const {path} = require('path');
let arg = undefined;
let mypath = path.join(__dirname, arg);
// The same error would occur.