node.js - 如何在 Sails.js 中使用 express-react-views?

标签 node.js express view reactjs sails.js

我试图通过在 config/views.js 中设置 engine: 'jsx', 来在 Sailsjs 中实现 express-react-views,但它返回以下错误:

info: Starting app...

warn: [Function]
error: Invalid view engine (jsx)-- are you sure it supports `consolidate`?
error: Your configured server-side view engine (jsx) could not be found.
error: Usually, this just means you need to install a dependency.
error: To install jsx, run:  `npm install jsx --save`
error: Otherwise, please change your `engine` configuration in config/views.js.
/Users/henry/Documents/dev/node/project/server/node_modules/sails/lib/hooks/views/configure.js:75
            throw e;
                  ^
Error

我应该如何在 Sails 项目中正确使用 express-react-views?

最佳答案

如果你关注this Tutorial你看到你必须将引擎设置为

engine: {
  ext: 'jsx',
  fn: require('express-react-views').createEngine()
}

安装 express-react-views 后,react 和 react-dom。对我来说,当将 View 文件的文件扩展名设置为 jsx 时,教程工作正常。

关于node.js - 如何在 Sails.js 中使用 express-react-views?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31495210/

相关文章:

node.js - 使用 mongoose 在 mongodb 中存储文件

node.js - 什么是 docker Node :9-stretch?

node.js - Angular2 与 NodeJ 一起使用

javascript - Node.js 在错误的文件路径上崩溃

iOS 5 查看事件顺序更改

java - CardView 上的自适应半径

Android Spinner 的 getSelectedView() 返回 null

javascript - node.js 中的 require(../) 是如何工作的?

node.js - passport.js passport.initialize() 中间件未使用

node.js - NodeJS | Express - 从根目录导航回来