2

我正在为我的 rails 4 应用程序使用react-rails 。使用反应模块的唯一方法是通过这种方法。一切都很好,没有问题。一直以来,我都在使用 chrome 版本 47.0.2526.106(64 位)。

使用任何其他浏览器,我得到React is not defined.

奇怪的是,如果我//= require reactapplication.js其中删除了消息,但我肯定会要求 React 两次,这会产生其他问题,因为 react 是必需components.jsReact = require('react');

简而言之,我正在使用react-rails gemand npm react。我只需要使用npm版本的react和react-rails的格式'<%= react_component() %>

关于为什么 chrome 没有任何问题而不是其他问题(firefox,safari)的任何解决方案。我没有尝试过资源管理器。

应用程序.js:

//= require jquery
//= require jquery_ujs
//= require foundation
//= require moment
//= require ckeditor/init
//= require components
//= require react-rails-hot-loader
//= require_tree .

...

组件.js:

//= require_self
//= require react_ujs

React = require('react');
ReactDOM = require('react-dom');
LinkedStateMixin = require('react-addons-linked-state-mixin');

...

错误堆栈:

//error stack:
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/Users/sylar/Sites/rails/simple-app/app/assets/javascripts/components/_stream_0.js":[function(require,module,exports){
var Dashboard = React.createClass({ 
  displayName: "Dashboard",

  render: function () {
    return React.createElement(
      "div",
      null,
      "Hi"
    );
  }

});
module.exports = Dashboard;
},{}]},{},["/Users/sylar/Sites/rails/simple-app/app/assets/javascripts/components/_stream_0.js"]);

包.json:

{
  "name": "simple-app",
  "dependencies": {
    "browserify": "~> 10.2.4",
    "browserify-incremental": "^3.0.1",
    "react": "^0.14.3",
    "react-addons-linked-state-mixin": "^0.14.3",
    "react-dom": "^0.14.3",
    "react-dropzone": "^3.3.0",
    "react-select": "^1.0.0-beta7",
    "reactify": "^1.1.1"
  },
  "engines": {
    "node": ">= 0.10"
  }
}

宝石文件:

source 'https://rubygems.org'
ruby '2.2.3'
gem 'rails', '4.2.4'
gem 'pg'
group :production do
  gem 'rails_12factor'
  gem 'puma'
end

gem 'sass-rails', '~> 5.0'
gem 'country_select'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'
gem 'foundation-rails'
gem 'momentjs-rails', '2.10.3'
gem 'react-rails', '~> 1.4.2'
gem "browserify-rails"
gem 'react-rails-hot-loader'
gem 'sidekiq', '4.0.1'
gem 'sinatra', require: false
gem 'slim'
gem 'ckeditor', '4.1.2'
gem 'devise', '3.5.2'
gem 'paperclip', '4.3.1'
gem 'aws-sdk', '< 2.0'

gem 'kaminari', '0.16.3'

gem 'awesome_print', :require => 'ap'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'stripe', '1.27.2'
# Use Figaro to hide secret keys
gem 'figaro', '1.1.1'
gem 'friendly_id', '5.1.0'

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'better_errors'
end
4

0 回答 0