【问题标题】:TypeError: Cannot read property 'split' of undefined in nodejs nodemonTypeError:无法读取nodejs nodemon中未定义的属性'split'
【发布时间】:2020-08-02 20:47:33
【问题描述】:

error img

反应/node.js 我不知道是什么问题。它说他们是nodemon中的错误。但是,我无法找出问题所在。 请帮帮我。

index.js:4 Uncaught TypeError: Cannot read property 'split' of undefined
    at Object.<anonymous> (index.js:4)
    at Object.../node_modules/nodemon/lib/utils/index.js (index.js:95)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.<anonymous> (run.js:3)
    at Object.../node_modules/nodemon/lib/monitor/run.js (run.js:459)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.../node_modules/nodemon/lib/monitor/index.js (index.js:2)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    ...

这里是代码

var noop = function () { };
var path = require('path');
const semver = require('semver');
//here is the problem. There is a 'split'.
var version = process.versions.node.split('.') || [null, null, null];

var utils = (module.exports = {
  semver: semver,
  satisfies: test => semver.satisfies(process.versions.node, test),
  version: {
    major: parseInt(version[0] || 0, 10),
    minor: parseInt(version[1] || 0, 10),
    patch: parseInt(version[2] || 0, 10),
  },
  clone: require('./clone'),
  merge: require('./merge'),
  bus: require('./bus'),
  isWindows: process.platform === 'win32',
  isMac: process.platform === 'darwin',
  isLinux: process.platform === 'linux',
  isRequired: (function () {
...

【问题讨论】:

  • 您能给我们看看代码吗?该错误表示您尝试拆分的字符串未定义,我们需要代码来查看原因。
  • 我改了帖子。
  • 请帮帮我..ㅠㅠ
  • 你能不能做 console.log(process.versions.node) 并给我们看结果
  • 结果未定义。

标签: reactjs npm server split nodemon


【解决方案1】:

如果您尝试获取版本,请使用 process.version 而不是 process.versions 属性。

process 应该是这样的。

process {
  version: 'v12.16.2',
  versions: {
    node: '12.16.2',
    v8: '7.8.279.23-node.34',
    uv: '1.34.2',
    zlib: '1.2.11',
    brotli: '1.0.7',
    ares: '1.15.0',
    modules: '72',
    nghttp2: '1.40.0',
    napi: '5',
    llhttp: '2.0.4',
    http_parser: '2.9.3',
    openssl: '1.1.1e',
    cldr: '36.0',
    icu: '65.1',
    tz: '2019c',
    unicode: '12.1'
  },
  arch: 'x64',
  platform: 'darwin',
  release: {
    name: 'node',
    lts: 'Erbium',
    sourceUrl: 'https://nodejs.org/download/release/v12.16.2/node-v12.16.2.tar.gz',
    headersUrl: 'https://nodejs.org/download/release/v12.16.2/node-v12.16.2-headers.tar.gz'
  },

【讨论】:

  • 1.打开你的终端/外壳。 2. 输入node。 3. 给我们输出(记得去掉敏感信息。)
【解决方案2】:

您正在尝试使用不存在的分隔符拆分字符串。 例如

...
  ares: '1.15.0',
  napi: '5',
...

如果您缺少值,请尝试用 0 替换,而不是默认为 null。

【讨论】:

    猜你喜欢
    • 2021-04-01
    • 2017-03-06
    • 2022-09-23
    • 2022-11-29
    • 2017-08-30
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多