错误:在部署云功能时解析触发器时出错 - Firebase

问题描述 投票:3回答:3

我正在使用renderToStringreact-dom函数(在我的服务器端)。代码看起来像(+/-):

import Home from './app/containers/Home';
const app = express();

app.get('**', (req, res) => {
  const html = renderToString(<Home />);
  res.set('Cache-Control', 'public, max-age=600, s-maxage=1200');
  res.send(html);
});

一切顺利,直到我尝试在服务器上部署它。

控制台中的示例错误:

Error: Error parsing triggers: Cannot find module 'store/Home/actions'

When it appears?

如果我将路径更改为其他组件(不使用任何其他组件(仅来自节点的模块,如reactreact-redux)),它可以正常工作。

但是,如果我尝试使用一些使用其他组件并导入它们的组件,例如:

var _CreateUser = require('components/Pages/CreateUser');(它在渲染组件中)

现在它将失败并出现错误:

Error: Error parsing triggers: Cannot find module 'components/Pages/CreateUser'

所以目前我卡住了,因为我必须在服务器端使用我的整个应用程序,而不仅仅是一个不导入任何内容的组件:)

为什么这样工作?为什么会失败?是不是webpack配置失败了?

期待任何帮助。谢谢。

请注意,正如我上面所说,如果我使用任何导入(不使用其中的任何其他组件)将某些组件渲染为字符串 - 服务器端渲染工作正常,并且我能够在页面加载之前看到renderedToString内容。

enter image description here

javascript reactjs firebase webpack google-cloud-functions
3个回答
3
投票

您导入本地模块的所有地方都需要在路径中包含该目录,否则它将在node_modules中搜索命名包并最终失败。

require('./store/Home/actions');

要么:

import HomeActions from './store/Home/actions';

...取决于您使用的导入样式。始终需要准确的目录作为import / require语句的一部分。


2
投票

您正在使用相对路径cd进入并从函数目录部署,因此它是正确的。


2
投票

看起来你的Home组件在functions/app/containers/Home内,你需要访问文件functions/app/store/Home/actions

containers/Home文件中,您需要将两个目录放到app文件夹中,然后转到两个目录以更正文件。所以

import HomeActions from '../../store/Home/actions'`. 

每个../表示将一个目录上传到父文件夹。我们去了

functions/app/containers/Home

functions/app/containers/

functions/app然后我们可以指定从那里继续的路径

store/Home/actions

© www.soinside.com 2019 - 2024. All rights reserved.