Client side NPM


#1

Hi

I’m following the guide at http://react-in-meteor.readthedocs.org/en/latest/client-npm/ and I tried adding react-dragula (https://www.npmjs.com/package/react-dragula) to my app.

I’ve done meteor add meteorhacks:npm cosmos:browserify

My packages.json

{
  "externalify": "0.1.0",
  "react-dragula": "1.0.2"
}

app.browserify.js

dragula = require('react-dragula');

app.browserify.options.json

{
  "transforms": {
    "react-dragula": {
      "global": true,
      "external": {
        "react": "React.require"
      }
    }
  }
}

But I get the following error:

C:\dev\tren-backend\packages\npm-container\.npm\package\node_modules\react-dragula\node_modules\dragula\node_modules\crossvent\node_modules\custom-event\index.js:24
'function' === typeof document.createEvent ? function CustomEvent (type, param
                      ^
ReferenceError: document is not defined

At first I was thinking this was because document isn’t available on server so I moved it from /lib to /client but I still get the same error. Do I have to transform it with something else?

Edit: Trying instead with react-dnd I get this error:


   While building the application:
   lib\browserify\app.browserify.js: Unexpected object exported by the
   "C:\\dev\\tren-backend\\packages\\npm-container\\.npm\\package\\node_modules\\react-dnd\\modules\\index.js"
   package. Expected a transform function.

Edit2: I removed the app.browserify.options.json and this makes react-dnd work (but not react-dragula). Will this be bad for my code?

Cheers


#2

I’m not sure, since the docs don’t explain how app.browserify.options.json works, but I think you need to just cut and paste from the guide. In other words, don’t change ‘externalify’ to ‘react-dragula’. That’s what I did and I at least got the app to build.

Of course it would be nice to actually understand what it’s doing.


#3

That makes the most sense, not sure why I did that. I’ll try do something else. Cheers.