moroshko/react-autosuggest

Webpack AMD setup references React.js, should be react.js

Open

#312 opened on Jan 1, 2017

View on GitHub
 (0 comments) (0 reactions) (0 assignees)JavaScript (5,936 stars) (637 forks)batch import
help wanted

Description

When I use RequireJS with react-autosuggest, I get a 404 load error when require.js tries to load http://localhost:9000/assets/javascripts/React.js . React has already been loaded at this point (from a Webjar) and is accessable as "react.js". I believe this is because the Webpack configuration for AMD, line 5 (below) from autosuggest.js, should not capitalize "React". I have tested this in my setup by changing this

(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("React"));
	else if(typeof define === 'function' && define.amd)
		define(["React"], factory);

to this

(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("React"));
	else if(typeof define === 'function' && define.amd)
		define(["react"], factory);

which fixes the problem for me , until I move to Production and want to load autosuggest from a CDN. I'm not sure what the rationale for capitalizing "React" in define may be- doesn't it reference react.js ?

FWIW, here's my require.js config (I have not yet been able to get a working WebJar built for this so had to load directly from the CDN), in coffescript

require.config
  paths:
    autosuggest: 'https://unpkg.com/react-autosuggest@7.0.1/dist/standalone/autosuggest.min'

used thus in a component that uses an autosuggest child

define [
  'react',
  'react-dom',
  'autosuggest'
], (React, ReactDOM, Autosuggest) ->
  class Picker extends React.Component
...

Contributor guide