felixrieseberg / React-Dropzone-Component

:camera: ReactJS Dropzone for File Uploads (using Dropzone.js)
MIT License
1k stars 154 forks source link

React is undefined #60

Closed gdowns67 closed 8 years ago

gdowns67 commented 8 years ago

hi there,

I'm having problems trying to run this component. I've installed the package using npm. Then I'm trying to 'require' it as follows - var DropzoneComponent = require('react-dropzone-component'); However, i then get an exception in icon.js - on this line: var React = (typeof window !== "undefined" ? window['React'] : typeof global !== "undefined" ? global['React'] : null);

React doesn't exist on the window object, so it's undefined.

The same is also true when clone the repo, run npm install, then gulp and open my browser here - http://localhost:8000/example/

It's trying to find React on the global object.

Can you anyone help? thanks

charleschenster commented 8 years ago

+1

I'm seeing this error also. Although I'm not using gulp and using browserify/watchify directly. Does that make a difference?

Here's my package.json file:

{
  ...
  "dependencies": {
    ...
    "react": "^0.14.7",
    "react-dropzone-component": "^0.9.0",
    ...
  },
  "devDependencies": {
    ...
    "browserify-shim": "^3.8.3",
    ...
  },
  "scripts": {
    "start": "watchify -o web/static/js/sample.js -v -d web/static/js/Sample.app.js",
    "build_deps": "browserify . --deps",
    "build": "browserify web/static/js/Sample.app.js -t [envify --NODE_ENV production] | uglifyjs -cm > web/static/js/sample.js",
  },
  "browserify": {
    "transform": [
      "reactify",
      "envify",
      "babelify"
    ]
  }
felixrieseberg commented 8 years ago

Hey, thanks for reporting! In order to not package React with the component, we need React to be available as a global object. So, for now, the solution here is to ensure that React is available globally.

If any of you have an idea on how we can both not have React inside the component, but also ensure that it's found if it isn't global, I'd love to find a solution :+1:

cgodkin commented 8 years ago

FWIW, I was having this problem too but after you fixed Issue #58, this problem is gone too. Thanks!