react / 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 () {
...
答案 0 :(得分:0)
如果要获取版本,请使用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 :(得分:0)
您试图用不存在的分隔符拆分字符串。 例如
...
ares: '1.15.0',
napi: '5',
...
如果缺少值,请尝试替换为 0,而不是默认为 null。