美文网首页
React Native 异常:var tmpDir = req

React Native 异常:var tmpDir = req

作者: 放羊娃华振 | 来源:发表于2023-01-10 09:29 被阅读0次

    首先看下错误信息,提示tmpDir 不是一个方法。

    /Users/mac/AndroidStudioProjects/source/reactnative/react-weather/node_modules/node-haste/lib/Cache/index.js:22
    var tmpDir = require('os').tmpDir();
                               ^
    
    TypeError: require(...).tmpDir is not a function
        at Object.<anonymous> (/Users/mac/AndroidStudioProjects/source/reactnative/react-weather/node_modules/node-haste/lib/Cache/index.js:22:28)
        at Module._compile (node:internal/modules/cjs/loader:1101:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
        at Object.require.extensions.<computed> [as .js] (/Users/mac/AndroidStudioProjects/source/reactnative/react-weather/node_modules/babel-register/lib/node.js:152:7)
        at Module.load (node:internal/modules/cjs/loader:981:32)
        at Function.Module._load (node:internal/modules/cjs/loader:822:12)
        at Module.require (node:internal/modules/cjs/loader:1005:19)
        at require (node:internal/modules/cjs/helpers:94:18)
        at Object.<anonymous> (/Users/mac/AndroidStudioProjects/source/reactnative/react-weather/node_modules/node-haste/lib/index.js:15:13)
        at Module._compile (node:internal/modules/cjs/loader:1101:14)
    

    在根据报错的路径找下去,路径/node_modules/node-haste/lib/Cache/index.js:22的代码正是:

    var tmpDir = require('os').tmpDir();
    

    发现是这个tmpDir方法变了,应该是tmpdir,所以改下这里的源码即可。

    var tmpDir = require('os').tmpdir();
    

    至于为啥要这么改可以看看别人总结的 利用nodejs获取当前操作系统的数据参数 文章。

    相关文章

      网友评论

          本文标题:React Native 异常:var tmpDir = req

          本文链接:https://www.haomeiwen.com/subject/wgppcdtx.html