const {something} = require (something) 在 Express 中不起作用

const {something} = require (something) doesn't work in Express

const something = require(something) 完美运行

但是 const {something} = require(something)报错

const {something} = require(something);
      ^

SyntaxError: Unexpected token {

您尝试做的是对声明的解构,自 NodeJS 版本 6.4+ 起可用,为了能够使用它,您需要升级您正在使用的 NodeJS 版本,或者如果您需要要使用早期版本,您应该使用 babel 来转换您的代码。