<p dir="auto">Hello<br>
It seems that having a local plugin in the <code class="notranslate">.babelrc</code> breaks babel-node.</p>
<p dir="auto">This is my <code class="notranslate">.babelrc</code> file:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;stage&quot;: 0,
  &quot;env&quot;: {
    &quot;development&quot;: {
      &quot;plugins&quot;: [&quot;./build/babelRelayPlugin&quot;, &quot;react-transform&quot;],
      &quot;sourceMaps&quot;: &quot;inline&quot;,
      &quot;optional&quot;: [
          &quot;runtime&quot;,
          &quot;es7.decorators&quot;,
          &quot;es7.classProperties&quot;
        ],
      &quot;extra&quot;: {
        &quot;react-transform&quot;: {
          &quot;transforms&quot;: [{
            &quot;transform&quot;: &quot;react-transform-hmr&quot;,
            &quot;imports&quot;: [&quot;react&quot;],
            &quot;locals&quot;: [&quot;module&quot;]
          }, {
            &quot;transform&quot;: &quot;react-transform-catch-errors&quot;,
            &quot;imports&quot;: [&quot;react&quot;, &quot;redbox-react&quot;]
          }]
        }
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">{
  "stage": 0,
  "env": {
    "development": {
      "plugins": ["./build/babelRelayPlugin", "react-transform"],
      "sourceMaps": "inline",
      "optional": [
          "runtime",
          "es7.decorators",
          "es7.classProperties"
        ],
      "extra": {
        "react-transform": {
          "transforms": [{
            "transform": "react-transform-hmr",
            "imports": ["react"],
            "locals": ["module"]
          }, {
            "transform": "react-transform-catch-errors",
            "imports": ["react", "redbox-react"]
          }]
        }
      }
    }
  }
}
</code></pre></div>
<p dir="auto">And this is my local <code class="notranslate">./build/babelRelayPlugin</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var getbabelRelayPlugin = require('babel-relay-plugin');
var schema = require('../data/schema.json');

module.exports = getbabelRelayPlugin(schema.data);"><pre class="notranslate"><code class="notranslate">var getbabelRelayPlugin = require('babel-relay-plugin');
var schema = require('../data/schema.json');

module.exports = getbabelRelayPlugin(schema.data);
</code></pre></div>
<p dir="auto">This results in the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt; babel-node ./devServer.js

C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\file\plugin-manager.js:164
      throw new TypeError(messages.get(&quot;pluginNotTransformer&quot;, name));
      ^

TypeError: The plugin &quot;./build/babelRelayPlugin.js&quot; didn't export a Plugin instance
    at PluginManager.validate (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\file\plugin-manager.js:164:13)
    at PluginManager.add (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\file\plugin-manager.js:213:10)
    at File.buildTransformers (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\file\index.js:237:21)
    at new File (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\file\index.js:139:10)
    at Pipeline.transform (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\pipeline.js:164:16)
    at Object.transformFileSync (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\api\node.js:137:37)
    at compile (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\api\register\node.js:132:20)
    at normalLoader (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\api\register\node.js:199:14)
    at Object.require.extensions.(anonymous function) [as .js] (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\api\register\node.js:216:7)
    at Module.load (module.js:355:32)"><pre class="notranslate"><code class="notranslate">&gt; babel-node ./devServer.js

C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\file\plugin-manager.js:164
      throw new TypeError(messages.get("pluginNotTransformer", name));
      ^

TypeError: The plugin "./build/babelRelayPlugin.js" didn't export a Plugin instance
    at PluginManager.validate (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\file\plugin-manager.js:164:13)
    at PluginManager.add (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\file\plugin-manager.js:213:10)
    at File.buildTransformers (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\file\index.js:237:21)
    at new File (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\file\index.js:139:10)
    at Pipeline.transform (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\transformation\pipeline.js:164:16)
    at Object.transformFileSync (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\api\node.js:137:37)
    at compile (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\api\register\node.js:132:20)
    at normalLoader (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\api\register\node.js:199:14)
    at Object.require.extensions.(anonymous function) [as .js] (C:\Users\bwessels.SPENDV\Documents\WebstormProjects\react-transform-boilerplate\node_modules\babel-core\lib\api\register\node.js:216:7)
    at Module.load (module.js:355:32)
</code></pre></div>
<p dir="auto">The only way I found to fix this is moving my local <code class="notranslate">babel-relay-plugin</code> into the <code class="notranslate">node_modules</code> folder and make it like being a complete package. That works but I would rather be able to use local plugins in my <code class="notranslate">.babelrc</code> file.</p>
<p dir="auto">Any ideas how to fix this?</p>
<p dir="auto">Thank you<br>
Bernd</p>
<p dir="auto">Minimal 100% repro case: <a href="https://gist.github.com/impinball/cfe04caff66f7547611a">https://gist.github.com/impinball/cfe04caff66f7547611a</a></p>
<p dir="auto"><strong>Expected:</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Success"><pre class="notranslate"><code class="notranslate">Success
</code></pre></div>
<p dir="auto"><strong>Found:</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$PWD/node_modules/babel/node_modules/babel-core/lib/transformation/file/plugin-manager.js:164
      throw new TypeError(messages.get(&quot;pluginNotTransformer&quot;, name));
      ^

TypeError: The plugin &quot;./plugin.js&quot; didn't export a Plugin instance
    at PluginManager.validate ($PWD/node_modules/babel/node_modules/babel-core/lib/transformation/file/plugin-manager.js:164:13)
    at PluginManager.add ($PWD/node_modules/babel/node_modules/babel-core/lib/transformation/file/plugin-manager.js:213:10)
    at File.buildTransformers ($PWD/node_modules/babel/node_modules/babel-core/lib/transformation/file/index.js:237:21)
    at new File ($PWD/node_modules/babel/node_modules/babel-core/lib/transformation/file/index.js:139:10)
    at Pipeline.transform ($PWD/node_modules/babel/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
    at Object.transformFileSync ($PWD/node_modules/babel/node_modules/babel-core/lib/api/node.js:137:37)
    at compile ($PWD/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:132:20)
    at normalLoader ($PWD/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:199:14)
    at Object.require.extensions.(anonymous function) [as .js] ($PWD/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:216:7)
    at Module.load (module.js:355:32)"><pre class="notranslate"><code class="notranslate">$PWD/node_modules/babel/node_modules/babel-core/lib/transformation/file/plugin-manager.js:164
      throw new TypeError(messages.get("pluginNotTransformer", name));
      ^

TypeError: The plugin "./plugin.js" didn't export a Plugin instance
    at PluginManager.validate ($PWD/node_modules/babel/node_modules/babel-core/lib/transformation/file/plugin-manager.js:164:13)
    at PluginManager.add ($PWD/node_modules/babel/node_modules/babel-core/lib/transformation/file/plugin-manager.js:213:10)
    at File.buildTransformers ($PWD/node_modules/babel/node_modules/babel-core/lib/transformation/file/index.js:237:21)
    at new File ($PWD/node_modules/babel/node_modules/babel-core/lib/transformation/file/index.js:139:10)
    at Pipeline.transform ($PWD/node_modules/babel/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
    at Object.transformFileSync ($PWD/node_modules/babel/node_modules/babel-core/lib/api/node.js:137:37)
    at compile ($PWD/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:132:20)
    at normalLoader ($PWD/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:199:14)
    at Object.require.extensions.(anonymous function) [as .js] ($PWD/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:216:7)
    at Module.load (module.js:355:32)
</code></pre></div>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/sebmck/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/sebmck">@sebmck</a>?</p>
<hr>
<p dir="auto"><strong>Edit:</strong> See the first comment for a better explanation.</p>
<hr>
<p dir="auto">The problem appears, from inserting <code class="notranslate">console.log</code>s in the generated output, to be caused by <a href="https://github.com/babel/babel/blob/master/packages/babel/src/transformation/file/plugin-manager.js#L82">this require</a> returning an empty object, as if by a circular require. The catch is that the file is never actually evaluated. And this only happens with relative requires.</p>
<p dir="auto">It seems to me like the problem is that Babel's require hook is getting in the way of parsing plugins given with relative paths, causing them to be required twice. The best fix IMHO is to explicitly ignore (without the ability to override) plugin files when transpiling.</p>