节点应用无法在mojave上运行:ReferenceError:未定义internalBinding

时间:2018-11-04 23:08:55

标签: node.js npm gulp node-gyp macos-mojave

我尝试无法成功运行节点应用程序,该节点应用程序在High Sierra和Windows 10上均可正常运行,但在Mojave 10.14.1上无法运行。 这是运行gulp build_dev任务时显示的错误:

[23:44:42] Requiring external module babel-register
fs.js:25
'use strict';
^

ReferenceError: internalBinding is not defined
    at fs.js:25:1
    at req_ (/Users/user1/Documents/NodeProjects/myapp/node_modules/natives/index.js:137:5)
    at Object.req [as require] (/Users/user1/Documents/NodeProjects/myapp/node_modules/natives/index.js:54:10)
    at Object.<anonymous> (/Users/user1/Documents/NodeProjects/myapp/node_modules/vinyl-fs/node_modules/graceful-fs/fs.js:1:37)
    at Module._compile (internal/modules/cjs/loader.js:707:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/user1/Documents/NodeProjects/myapp/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
    at Function.Module._load (internal/modules/cjs/loader.js:536:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myapp@1.0.0 dev: `node node_modules/gulp/bin/gulp.js build_dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the myapp@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/user1/.npm/_logs/2018-11-04T22_44_42_709Z-debug.log

这是package.json文件的内容,其中包含应用程序中使用的所有依赖项:

{
  "name": "myapp",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test-dev": "node node_modules/gulp/bin/gulp.js test_dev",
    "test-prod": "node node_modules/gulp/bin/gulp.js test_prod",
    "dev": "node node_modules/gulp/bin/gulp.js build_dev",
    "prod": "node node_modules/gulp/bin/gulp.js build_prod"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel-polyfill": "^6.26.0",
    "body-parser": "^1.17.2",
    "cookie-parser": "^1.4.3",
    "envify": "^4.1.0",
    "express": "^4.16.2",
    "glob": "^7.1.2",
    "http-status-codes": "^1.1.6",
    "morgan": "^1.8.2",
    "multi-glob": "^1.0.1",
    "npm": "^6.4.1",
    "path": "^0.12.7"
  },
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-core": "^6.26.0",
    "babel-plugin-syntax-async-functions": "^6.13.0",
    "babel-plugin-transform-async-to-generator": "^6.24.1",
    "babel-preset-env": "^1.6.0",
    "babel-register": "^6.24.1",
    "babelify": "^7.3.0",
    "browser-sync": "^2.26.3",
    "browserify": "^16.1.0",
    "gulp": "^3.9.1",
    "gulp-concat": "^2.6.1",
    "gulp-if": "^2.0.2",
    "gulp-imagemin": "^3.3.0",
    "gulp-minify-css": "^1.2.4",
    "gulp-nodemon": "^2.2.1",
    "gulp-notify": "^3.0.0",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^3.1.0",
    "gulp-sass-glob": "^1.0.8",
    "gulp-sourcemaps": "^2.6.0",
    "gulp-uglify": "^3.0.0",
    "gulp-util": "^3.0.8",
    "imagemin-pngquant": "^5.0.1",
    "run-sequence": "^2.2.0",
    "vinyl-buffer": "^1.0.0",
    "vinyl-source-stream": "^1.1.0"
  }
}

关于如何调试此问题的任何提示?可能与gcc编译器版本有关吗?

节点版本:11.1.0 npm版本:6.4.1

在此链接上,我上传了“ npm install”命令的日志以安装依赖项:npm_install.log

3 个答案:

答案 0 :(得分:18)

尝试将natives更新到最新版本。 This提交似乎可以解决您遇到的问题。

答案 1 :(得分:6)

我将Node版本从10.15.0(LTS)降级到10.10.0。这是我修复的internalBinding错误。

sudo npm cache clean -f
sudo npm install -g n
sudo n 10.10.0

答案 2 :(得分:1)

就我而言,问题在于node_modules安装,因此请执行以下操作。

  • 执行require(tidyxl) colnames <- c("Item","Score","Mean") excelfile <- "FormattedSheet.xlsx" x <- xlsx_cells(excelfile) # Find all cells with character values: return their address (i.e., Cell) and character (i.e., Value) chars <- x[x$data_type == "character", c("address", "character")] starting.positions <- unlist( chars[which(chars$character %in% colnames), "address"] ) # returns: c(C6, D6, E6)
  • 检查您是否有任何严重漏洞
  • 要么升级模块的版本,要么搜索备用模块。
  • yarn audit
  • 你应该很好走

注意:在我看来,节点版本不是问题,它只是一个易受攻击的模块(gulp-angular-templatecache)。如果上述方法无效,我还建议您使用yarn installnpm upgrade

npm rebuild不适用于私有存储库,但npm audit可用。