node.js - 引用错误 : path is not defined: Express

标签 node.js reactjs express

该页面已呈现,但当我按下任何链接时出现错误。

ReferenceError: path is not defined
at app.get (/var/www/example.com/example-domain/server.js:106:19)
at Layer.handle [as handle_request] (/var/www/example.com/example-domain/node_modules/express/lib/router/layer.js:95:5)
at next (/var/www/example.com/example-domain/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/var/www/example.com/example-domain/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/var/www/example.com/example-domain/node_modules/express/lib/router/layer.js:95:5)
at /var/www/example.com/example-domain/node_modules/express/lib/router/index.js:281:22
at param (/var/www/example.com/example-domain/node_modules/express/lib/router/index.js:354:14)
at param (/var/www/example.com/example-domain/node_modules/express/lib/router/index.js:365:14)
at Function.process_params (/var/www/example.com/example-domain/node_modules/express/lib/router/index.js:410:3)
at next (/var/www/example.com/example-domain/node_modules/express/lib/router/index.js:275:10)

这是来自 server.js 的代码:
app.use(express.static('../build'));
app.get('*', (req, res)=> {
  const index = path.join(__dirname, '/', '../build', 'index.html' );
  res.sendFile(index);
});

提前致谢。

最佳答案

在文件的头部,只需添加

const path = require('path');

关于node.js - 引用错误 : path is not defined: Express,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58801984/

相关文章:

node.js - Loopback 上的 MongoDB 聚合

php - NodeJS Oboe 不向 PHP 服务器发送请求正文

reactjs - 测试素材-ui按钮文字

javascript - 当服务器无法访问时如何清除cookie

javascript - Bluebird — 在处理程序中创建了一个 promise ,但没有从中返回

node.js - 使用 Passport js 进行身份验证时 Sequelize Js 错误(facebook)

javascript - 如何在reactjs中将一个组件插入到另一个组件onclick?

javascript - 无法初始化商店的状态

mongodb - Graphql 创建两个查询之间的关系。错误无法在初始化之前访问

node.js - 使用 reactjs(非原生)从我的网站创建一个移动应用程序