{"action":"created","issue":{"url":"https://api.github.com/repos/babel/babelify/issues/175","labels_url":"https://api.github.com/repos/babel/babelify/issues/175/labels{/name}","comments_url":"https://api.github.com/repos/babel/babelify/issues/175/comments","events_url":"https://api.github.com/repos/babel/babelify/issues/175/events","html_url":"https://github.com/babel/babelify/issues/175","id":128365356,"number":175,"title":"Breaks Browserify's require() method","user":{"login":"ericbiewener","id":253298,"avatar_url":"https://avatars.githubusercontent.com/u/253298?v=3","gravatar_id":"","url":"https://api.github.com/users/ericbiewener","html_url":"https://github.com/ericbiewener","followers_url":"https://api.github.com/users/ericbiewener/followers","following_url":"https://api.github.com/users/ericbiewener/following{/other_user}","gists_url":"https://api.github.com/users/ericbiewener/gists{/gist_id}","starred_url":"https://api.github.com/users/ericbiewener/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericbiewener/subscriptions","organizations_url":"https://api.github.com/users/ericbiewener/orgs","repos_url":"https://api.github.com/users/ericbiewener/repos","events_url":"https://api.github.com/users/ericbiewener/events{/privacy}","received_events_url":"https://api.github.com/users/ericbiewener/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-24T01:28:26Z","updated_at":"2016-01-25T13:27:51Z","closed_at":"2016-01-25T02:02:41Z","body":"I am unable to use `require('../path/to/file.js')` after Babelify transforms my code. It appears that the `require()` method is no longer the one required to make that syntax work. Instead, whatever undesired `required` method has taken its place always returns either an empty object `{}` or `undefined`.\r\n\r\nIf, however, I add `require = window.require` to the top of the page, then everything works fine. To be clear, Browserify was working fine prior to adding the Babelify transform.\r\n\r\nI first encountered this when using `require()` in my own code. Trying to use something like `React = require('react')` is resulting in `React` being undefined. I posted on StackOverflow about it [here] (http://stackoverflow.com/questions/34839456/using-babelify-to-compile-react-results-in-react-router-being-undefined/34965407#34965407), thinking that I found the answer in simply switching to ES2015's `import` syntax. However, I am now getting the same error in a node package that is using the `require` syntax. Specifically, I'm using the [ffmetadata] (https://www.npmjs.com/package/ffmetadata) package. It's main `index.js` file begins with the following:\r\n\r\n```\r\nvar spawn = require(\"child_process\").spawn,\r\n\tffmpeg = spawn.bind(null, process.env.FFMPEG_PATH || \"ffmpeg\"),\r\n```\r\n\r\nThat second line throws the error:\r\n\r\n`Uncaught TypeError: Cannot read property 'bind' of undefined`\r\n\r\nThe `spawn` variable is undefined. For some slight debugging, I logged the value of `require(\"child_process\")` to the console, which resulted in an empty object `{}`.\r\n\r\nIn poking around further, I realized that I could paste those two lines of code directly into my console and they'd work fine. This is how I discovered that the desired global `require()` method was not the one actually getting used. As I said earlier, putting `require = window.require` at the top of the necessary files solves the issue.\r\n\r\nIn case it helps, I am using Browserify via gulp, with the following code:\r\n```\r\ngulp.task('js', function() {\r\n\tvar browserify = require('browserify'),\r\n\t\t\twatchify   = require('watchify'),\r\n\t\t\tbabelify   = require('babelify');\r\n\r\n\tfunction bundle() {\r\n\t\tb.bundle()\r\n\t\t\t.on('error', function(error){\r\n\t\t\t\tgutil.log(error);\r\n\t\t\t})\r\n\t\t\t.pipe(source('app.js'))\r\n\t\t\t.pipe(gulp.dest(paths.client.js.build))\r\n\t}\r\n\r\n\tvar b = browserify({\r\n\t\tcache: {},\r\n\t\tpackageCache: {},\r\n\t\tentries: paths.client.js.dev,\r\n\t\tdebug: true,\r\n\t\tplugin: [watchify]\r\n\t})\r\n\t.transform(babelify, {presets: ['es2015', 'react']})\r\n\r\n\tb.on('update', function(){\r\n\t\tbundle();\r\n\t});\r\n\r\n\tb.on('log', gutil.log);\r\n\tbundle();\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/babel/babelify/issues/comments/174509414","html_url":"https://github.com/babel/babelify/issues/175#issuecomment-174509414","issue_url":"https://api.github.com/repos/babel/babelify/issues/175","id":174509414,"user":{"login":"ericbiewener","id":253298,"avatar_url":"https://avatars.githubusercontent.com/u/253298?v=3","gravatar_id":"","url":"https://api.github.com/users/ericbiewener","html_url":"https://github.com/ericbiewener","followers_url":"https://api.github.com/users/ericbiewener/followers","following_url":"https://api.github.com/users/ericbiewener/following{/other_user}","gists_url":"https://api.github.com/users/ericbiewener/gists{/gist_id}","starred_url":"https://api.github.com/users/ericbiewener/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericbiewener/subscriptions","organizations_url":"https://api.github.com/users/ericbiewener/orgs","repos_url":"https://api.github.com/users/ericbiewener/repos","events_url":"https://api.github.com/users/ericbiewener/events{/privacy}","received_events_url":"https://api.github.com/users/ericbiewener/received_events","type":"User","site_admin":false},"created_at":"2016-01-25T13:27:51Z","updated_at":"2016-01-25T13:27:51Z","body":"Sorry about that misleading code -- I was writing it for an Electron app, which does in fact provide the child_process (and everything else in node) to the app. As I mentioned, the same thing happens when trying to `require()` react as well. I actually posted about this on StackOverflow [here] (http://stackoverflow.com/questions/34839456/using-babelify-to-compile-react-results-in-react-router-being-undefined/34965407#34965407) a little while back when building an app *not* in Electron, but just a standard web app.\r\n\r\nSo I'm getting the same result when building a standard web app, and when trying to `require` a front-end node module like React."}}