简体   繁体   English

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

[英]Error: Error parsing triggers while deploying cloud functions - Firebase

I'm using renderToString function from react-dom (on my server side). 我正在使用来自react-dom renderToString函数(在我的服务器端)。 The code looks like (+/-): 代码看起来像(+/-):

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);
});

Everything goes smooth, until I try to deploy it on the server. 一切顺利,直到我尝试在服务器上部署它。

Example error in the console: 控制台中的示例错误

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

When it appears? 什么时候出现?

If I change my path to some other component, which does not use any other components (only modules from node, like react or react-redux ) it works correctly . 如果我将路径更改为其他组件( 不使用任何其他组件(仅来自节点的模块,如reactreact-redux )),它可以正常工作

But if I try to use some component which uses other components and imports them, eg: 但是如果我尝试使用一些使用其他组件并导入它们的组件,例如:

var _CreateUser = require('components/Pages/CreateUser'); (it's in the rendered component) (它在渲染组件中)

Now it will fail with error: 现在它将失败并出现错误:

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

So currently Im stuck, because I have to use my whole app on server side, not just a single component which doesn't import anything :) 所以目前我卡住了,因为我必须在服务器端使用我的整个应用程序,而不仅仅是一个不导入任何内容的组件:)

Why does it work this way? 为什么这样工作? Why does it fail? 为什么会失败? Is it bad webpack config fail? 是不是webpack配置失败了?

Looking forward for any help. 期待任何帮助。 Thank you. 谢谢。

Note , as I said above, if I render to string some component with any imports (that doesn't use any other component in it) - the server side rendering works fine and Im able to see the renderedToString content before page loads. 请注意 ,正如我上面所说,如果我使用任何导入(不使用其中的任何其他组件)将某些组件渲染为字符串 - 服务器端渲染工作正常,并且我能够在页面加载之前看到renderedToString内容。

在此输入图像描述

Everywhere you import local modules you need to include the directory in the path otherwise it will search node_modules for a named package and ultimately fail. 您导入本地模块的所有地方都需要在路径中包含该目录,否则它将在node_modules中搜索命名包并最终失败。

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

Or: 要么:

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

...depending on which import style you're using. ...取决于您使用的导入样式。 An accurate directory is always needed as a part of the import/require statement. 始终需要准确的目录作为import / require语句的一部分。

您使用的是相对路径, cd中以及从功能目录部署所以它是正确的。

It looks like your Home component is inside functions/app/containers/Home and you need access to the file functions/app/store/Home/actions . 看起来您的Home组件位于functions/app/containers/Home ,您需要访问文件functions/app/store/Home/actions

From your containers/Home file, you need to go up two directories to the app folder, then go down two directories to correct file. 从你的containers/Home文件,你需要两个目录app文件夹,然后走下来两个目录,以正确的文件。 So 所以

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

Each ../ represents going up one directory to the parent folder. 每个../表示将一个目录上传到父文件夹。 We went from 我们去了

functions/app/containers/Home to functions/app/containers/Home to

functions/app/containers/ to functions/app/containers/ to

functions/app and then we can specify which path to continue on from there with functions/app然后我们可以指定从那里继续的路径

store/Home/actions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解析功能触发器时出现Firebase错误 - Cloud Functions for Firebase Error occurred while parsing your function triggers 部署Firebase云功能时发生意外错误 - Unexpected error while deploying firebase cloud functions 部署Firebase时解析错误 - Parsing error while deploying firebase Firebase函数部署错误:解析函数触发器时发生错误 - Firebase Functions deploy error : Error occurred while parsing your function triggers Firebase部署错误:解析函数触发器时发生错误 - Firebase Deploy Error: Error occurred while parsing your function triggers firebase部署错误:“解析函数触发器时发生错误” - firebase deployment error:“error occured while parsing your function triggers” 部署 Firebase 云发布订阅代码时出错 - getting error while deploying firebase cloud pub-sub code 部署 Firebase 函数时出错:无法找到模块 - Error while deploying Firebase functions: Unable to find module Firebase:解析触发器时出错:无法找到模块&#39;request-promise&#39;简单云功能 - Firebase: Error parsing triggers: Cannot find module 'request-promise' simple cloud function 获取 `eslint' - 解析错误,同时编译 firebase 云 function - Getting `eslint' - parsing error, while compiling firebase cloud function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM