Javascript React(404)中未找到流星法

Javascript React(404)中未找到流星法,javascript,reactjs,meteor,methods,Javascript,Reactjs,Meteor,Methods,我很难将React整合到Meteor中,一些非常奇怪的事情正在发生 我有一个组件,我正在从中调用Meteor方法,我只是先做一些测试,看看是否一切都如预期的那样工作(在我使用Blaze时它工作了),但在Meteor方法调用之后,我得到了一个方法“[Meteor method name]”未找到,带有404 错误: ---------------prev-inv meteor.js?hash=27829e9…:932 Exception while simulating the effect of

我很难将React整合到Meteor中,一些非常奇怪的事情正在发生

我有一个组件,我正在从中调用Meteor方法,我只是先做一些测试,看看是否一切都如预期的那样工作(在我使用Blaze时它工作了),但在Meteor方法调用之后,我得到了一个
方法“[Meteor method name]”未找到
,带有
404

错误:

---------------prev-inv
meteor.js?hash=27829e9…:932 Exception while simulating the effect of invoking 'cloudinaryImageContents.insert' _class {error: "validation-error", reason: ""name" is required", details: Array(1), message: ""name" is required [validation-error]", errorType: "Meteor.Error"…} Error
    at new _class (http://localhost:3001/packages/mdg_validation-error.js?hash=c824fee078386259563451e9fa961549731965f5:71:89)
    at throwError (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:10660:17)
    at Validator.validate (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:10691:11)
    at Object.Validators.(anonymous function) [as required] (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:10707:19)
    at ScalarField.validate (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:2411:20)
    at ScalarField.validate (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:2807:33)
    at http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:11584:13
    at catchValidationError (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:11513:7)
    at http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:11582:5
    at arrayEach (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:13376:11)
ImageContentAddPage.jsx:26 ---------------after-inv
ImageContentAddPage.jsx:23 errorClass {error: 404, reason: "Method 'cloudinaryImageContents.insert' not found", details: undefined, message: "Method 'cloudinaryImageContents.insert' not found [404]", errorType: "Meteor.Error"…} undefined
ImageContentAddPage.jsx:24 -----inv
import React, { Component } from 'react';
import TextField from 'material-ui/TextField';
import RaisedButton from 'material-ui/RaisedButton';

import PageSection from '/imports/ui/components/Misc/PageSection';
import ImageUploaderMiddleware from '/imports/ui/components/Middleware/ImageUploaderMiddleware';
import CreatorMiddleware from '/imports/ui/components/Middleware/CreatorMiddleware';

import '/imports/api/contents/images/CloudinaryImage/methods.js';

export default class ImageContentAddPage extends CreatorMiddleware {
  componentWillMount(){
    this.setState({
      path: '/some/path',
      methodName: 'cloudinaryImageContents.insert',
      data: {}
    });
  }

  handleCreate(){
    console.log('---------------prev-inv');
    Meteor.call( this.state.methodName, this.state.data, function(err, res){
      console.log(err, res);
      console.log('-----inv');
    });
    console.log('---------------after-inv');
  }

  render () {
    return (
      <div>
        <TextField hintText="Image name" floatingLabelText="Name" />
        <TextField hintText="Image description" floatingLabelText="Description" />
        <ImageUploaderMiddleware>
        <RaisedButton label="Upload" primary />
        </ImageUploaderMiddleware>
        <div>
          {this.state.error ? this.state.error.reason : null}
        </div>
        <RaisedButton label="Create" primary onTouchTap={this.handleCreate.bind(this)} />
      </div>
    );
  }
}
Meteor.methods({
  'cloudinaryImageContents.insert'(image){
    image = image || {};
    image.userId = this.userId;
    let newImage = new CloudinaryImageContent(image);
    return newImage.save();
  }
});
组件:

---------------prev-inv
meteor.js?hash=27829e9…:932 Exception while simulating the effect of invoking 'cloudinaryImageContents.insert' _class {error: "validation-error", reason: ""name" is required", details: Array(1), message: ""name" is required [validation-error]", errorType: "Meteor.Error"…} Error
    at new _class (http://localhost:3001/packages/mdg_validation-error.js?hash=c824fee078386259563451e9fa961549731965f5:71:89)
    at throwError (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:10660:17)
    at Validator.validate (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:10691:11)
    at Object.Validators.(anonymous function) [as required] (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:10707:19)
    at ScalarField.validate (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:2411:20)
    at ScalarField.validate (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:2807:33)
    at http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:11584:13
    at catchValidationError (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:11513:7)
    at http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:11582:5
    at arrayEach (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:13376:11)
ImageContentAddPage.jsx:26 ---------------after-inv
ImageContentAddPage.jsx:23 errorClass {error: 404, reason: "Method 'cloudinaryImageContents.insert' not found", details: undefined, message: "Method 'cloudinaryImageContents.insert' not found [404]", errorType: "Meteor.Error"…} undefined
ImageContentAddPage.jsx:24 -----inv
import React, { Component } from 'react';
import TextField from 'material-ui/TextField';
import RaisedButton from 'material-ui/RaisedButton';

import PageSection from '/imports/ui/components/Misc/PageSection';
import ImageUploaderMiddleware from '/imports/ui/components/Middleware/ImageUploaderMiddleware';
import CreatorMiddleware from '/imports/ui/components/Middleware/CreatorMiddleware';

import '/imports/api/contents/images/CloudinaryImage/methods.js';

export default class ImageContentAddPage extends CreatorMiddleware {
  componentWillMount(){
    this.setState({
      path: '/some/path',
      methodName: 'cloudinaryImageContents.insert',
      data: {}
    });
  }

  handleCreate(){
    console.log('---------------prev-inv');
    Meteor.call( this.state.methodName, this.state.data, function(err, res){
      console.log(err, res);
      console.log('-----inv');
    });
    console.log('---------------after-inv');
  }

  render () {
    return (
      <div>
        <TextField hintText="Image name" floatingLabelText="Name" />
        <TextField hintText="Image description" floatingLabelText="Description" />
        <ImageUploaderMiddleware>
        <RaisedButton label="Upload" primary />
        </ImageUploaderMiddleware>
        <div>
          {this.state.error ? this.state.error.reason : null}
        </div>
        <RaisedButton label="Create" primary onTouchTap={this.handleCreate.bind(this)} />
      </div>
    );
  }
}
Meteor.methods({
  'cloudinaryImageContents.insert'(image){
    image = image || {};
    image.userId = this.userId;
    let newImage = new CloudinaryImageContent(image);
    return newImage.save();
  }
});

如果您正在为收藏
API
和方法使用
/imports
文件夹,请确保将方法文件导入服务器入口点(
/server/main.js
),否则,您的方法在服务器端将不可见。

您确定定义该方法的文件已捆绑在您的服务器上吗?根据Meteor文档,我在/imports文件夹中使用的所有内容。请看,这并不意味着它是捆绑的(事实上,这意味着它不是自动捆绑的)。您应该从
/imports
之外的入口点导入它(通常在
/server/main.js
文件中)。你是对的。刚刚将方法文件导入到我的服务器入口点,它按预期工作。我以前使用的是顶级/collections文件夹,但现在我正在对/imports进行重构,这就是为什么以前会导入它,但一旦我将内容移动到/imports文件夹,它就停止工作了。谢谢