thlorenz / browserify-shim

📩 Makes CommonJS incompatible files browserifyable.
MIT License
934 stars 87 forks source link

can not transform react in react-redux #209

Closed Tankpt closed 8 years ago

Tankpt commented 8 years ago

Here is my config

"dependencies":{
  "react": "^0.14.0",
  "react-dom": "^0.14.0",
  "react-redux": "^4.0.4",
  "redux": "^3.0.0",
},
"devDependencies":{
  "browserify": "~13.0.0",
  "browserify-shim": "~3.8.12",
},
"browserify": {
  "transform": [ "browserify-shim" ]
},
"browserify-shim": {
  "react": "global:React",
  "react-dom": "global:ReactDOM"
},
browserify -x react -x react-dom -s redux -e ./node_modules/react-redux > redux.js

I still find require('react') in the build file

var _react = require('react');
Tankpt commented 8 years ago

I just find in react-redux package.jon . react do not as a dependencies but as a peerDependencies 。 In npm3 peerDependencies will not install?

Will this peerDependencies caus the error?

bendrucker commented 8 years ago

Hard to say without code. We'll need a reproducible project to look further.

Tankpt commented 8 years ago

Thanks for you reply. And I made a demo as follow. https://github.com/Tankpt/react-redux I just package the react-redux with 'npm run redux'.

bendrucker commented 8 years ago

Ah. Browserify doesn't transform stuff in your node_modules folder. You have to run it as a global transform:

{
  "name": "react-redux",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "redux": "rm -rf react-redux.js && browserify -g browserify-shim -x react -s ReactRedux -e ./node_modules/react-redux > react-redux.js"
  },
  "repository": {
    "type": "git",
    "url": "git@github.com:Tankpt/react-redux.git"
  },
  "keywords": [],
  "license": "MIT",
  "homepage": "https://github.com/Tankpt/react-redux",
  "dependencies": {
    "react-redux": "^4.0.4",
    "redux": "^3.0.0"
  },
  "devDependencies": {
    "browserify": "~13.0.0",
    "browserify-shim": "~3.8.12"
  },
  "browserify-shim": {
    "react": "global:React"
  }
}
Tankpt commented 8 years ago

Thx