<blockquote>
<p dir="auto">Issue originally made by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/vadzim/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/vadzim">@vadzim</a></p>
</blockquote>
<h3 dir="auto">Bug information</h3>
<ul dir="auto">
<li><strong>Babel version:</strong> 6.3.17 (babel-core 6.3.17)</li>
<li><strong>Node version:</strong> v5.1.1</li>
<li><strong>npm version:</strong> 3.3.12</li>
</ul>
<h3 dir="auto">Options</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="--no-babelrc --presets es2015"><pre class="notranslate"><code class="notranslate">--no-babelrc --presets es2015
</code></pre></div>
<h3 dir="auto">Input code</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var x = { method() {
   var f = () =&gt; console.log( this.method, null &amp;&amp; method )
   f()
} }
x.method()"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span> <span class="pl-en">method</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
   <span class="pl-k">var</span> <span class="pl-en">f</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">method</span><span class="pl-kos">,</span> <span class="pl-c1">null</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">method</span> <span class="pl-kos">)</span>
   <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span> <span class="pl-kos">}</span>
<span class="pl-s1">x</span><span class="pl-kos">.</span><span class="pl-en">method</span><span class="pl-kos">(</span><span class="pl-kos">)</span></pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">Babel generated code fails:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt; echo &quot;var x = { method() {
   var f = () =&gt; console.log( this.method, null &amp;&amp; method )
   f()
} }
x.method()&quot; | ./node_modules/.bin/babel --no-babelrc --presets es2015 | node
[stdin]:17
            return console.log(_this.method, null &amp;&amp; method);
                                    ^

TypeError: Cannot read property 'method' of undefined
    at f ([stdin]:17:37)
    at Object.&lt;anonymous&gt; ([stdin]:19:9)
    at Object.method ([stdin]:7:28)
    at [stdin]:22:3
    at Object.exports.runInThisContext (vm.js:54:17)
    at Object.&lt;anonymous&gt; ([stdin]-wrapper:6:22)
    at Module._compile (module.js:425:26)
    at node.js:589:27
    at doNTCallback0 (node.js:430:9)
    at process._tickCallback (node.js:359:13)
&gt;"><pre class="notranslate"><code class="notranslate">&gt; echo "var x = { method() {
   var f = () =&gt; console.log( this.method, null &amp;&amp; method )
   f()
} }
x.method()" | ./node_modules/.bin/babel --no-babelrc --presets es2015 | node
[stdin]:17
            return console.log(_this.method, null &amp;&amp; method);
                                    ^

TypeError: Cannot read property 'method' of undefined
    at f ([stdin]:17:37)
    at Object.&lt;anonymous&gt; ([stdin]:19:9)
    at Object.method ([stdin]:7:28)
    at [stdin]:22:3
    at Object.exports.runInThisContext (vm.js:54:17)
    at Object.&lt;anonymous&gt; ([stdin]-wrapper:6:22)
    at Module._compile (module.js:425:26)
    at node.js:589:27
    at doNTCallback0 (node.js:430:9)
    at process._tickCallback (node.js:359:13)
&gt;
</code></pre></div>
<p dir="auto">while code without compilation works in node pretty well:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt; echo &quot;var x = { method() {
   var f = () =&gt; console.log( this.method, null &amp;&amp; method )
   f()
} }
x.method()&quot; | node
[Function: method] null
&gt;"><pre class="notranslate"><code class="notranslate">&gt; echo "var x = { method() {
   var f = () =&gt; console.log( this.method, null &amp;&amp; method )
   f()
} }
x.method()" | node
[Function: method] null
&gt;
</code></pre></div>
<p dir="auto">The problem is that babel loses this pointer. Generated code is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

var _this = undefined;
var x = {
    method: (function (_method) {
        function method() {
            return _method.apply(this, arguments);
        }

        method.toString = function () {
            return _method.toString();
        };

        return method;
    })(function () {
        var f = function f() {
            return console.log(_this.method, null &amp;&amp; method);
        };
        f();
    })
};
x.method();"><pre class="notranslate"><code class="notranslate">"use strict";

var _this = undefined;
var x = {
    method: (function (_method) {
        function method() {
            return _method.apply(this, arguments);
        }

        method.toString = function () {
            return _method.toString();
        };

        return method;
    })(function () {
        var f = function f() {
            return console.log(_this.method, null &amp;&amp; method);
        };
        f();
    })
};
x.method();
</code></pre></div>
<p dir="auto">The problem appers when method is accessed by its name in its body.</p>
<p dir="auto">I'm building an SSR template, and when I use @babebl/register and then execute webpack (config), the system reported an error.<br>
I tried @babel/polyfill and @babel/plugin-transform-runtime, but none of them worked.</p>
<h3 dir="auto">Input code</h3>
<p dir="auto"><code class="notranslate">index.js:</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="require(&quot;ignore-styles&quot;);
require(&quot;@babel/register&quot;)({
  ignore: [/\/(build|node_modules)\//],
  presets: [&quot;@babel/preset-env&quot;, &quot;@babel/preset-react&quot;],
  plugins: [&quot;@babel/plugin-syntax-dynamic-import&quot;, &quot;dynamic-import-node&quot;]
});
require(&quot;./server&quot;);"><pre class="notranslate"><code class="notranslate">require("ignore-styles");
require("@babel/register")({
  ignore: [/\/(build|node_modules)\//],
  presets: ["@babel/preset-env", "@babel/preset-react"],
  plugins: ["@babel/plugin-syntax-dynamic-import", "dynamic-import-node"]
});
require("./server");
</code></pre></div>
<p dir="auto"><code class="notranslate">server.js</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const config = require('../config/webpack.dev.config.js')
const webpack = require('webpack')
const express = require('express')
const webpackDevMiddleware = require('webpack-dev-middleware') 
const reactRouter = require('react-router')
const StaticRouter = reactRouter.reactRouter;
const app = express()
const complier = webpack(config)
const PORT = 8090
...
app.use(webpackDevMiddleware(complier, {
  publicPath: config.output.publicPath
}))

app.listen(PORT , function() {
  console.log(`SSR running on port ${PORT }`);
})"><pre class="notranslate"><code class="notranslate">const config = require('../config/webpack.dev.config.js')
const webpack = require('webpack')
const express = require('express')
const webpackDevMiddleware = require('webpack-dev-middleware') 
const reactRouter = require('react-router')
const StaticRouter = reactRouter.reactRouter;
const app = express()
const complier = webpack(config)
const PORT = 8090
...
app.use(webpackDevMiddleware(complier, {
  publicPath: config.output.publicPath
}))

app.listen(PORT , function() {
  console.log(`SSR running on port ${PORT }`);
})
</code></pre></div>
<p dir="auto"><code class="notranslate">webpack.dev.config.js</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const paths = require('./paths')
const webpack = require('webpack')
const htmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  entry: ['webpack-hot-middleware/client?reload=true', paths.appIndexJs],
  output: {
    path: paths.clientBuild,
    filename: '[name].bundle.js',
    chunkFilename: '[name].bundle.js',
    publicPath: paths.publicPath
  },
  devtool: 'eval-source-map',
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        options: {
          presets: [
            ['@babel/preset-env', { 
              useBuiltIns: 'usage', 
              corejs: &quot;2&quot;,  
              targets: {
                  browsers: ['last 2 versions', 'ie &gt;= 9'],
              },
            }],
            '@babel/preset-react'
          ]
        }
      }
    ]
  },
  resolve: {
    extensions: ['.js', '.jsx']
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new htmlWebpackPlugin({
      template: './client/index.html',
      filename: 'index.html'
    })
  ]
}"><pre class="notranslate"><code class="notranslate">const paths = require('./paths')
const webpack = require('webpack')
const htmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  entry: ['webpack-hot-middleware/client?reload=true', paths.appIndexJs],
  output: {
    path: paths.clientBuild,
    filename: '[name].bundle.js',
    chunkFilename: '[name].bundle.js',
    publicPath: paths.publicPath
  },
  devtool: 'eval-source-map',
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        options: {
          presets: [
            ['@babel/preset-env', { 
              useBuiltIns: 'usage', 
              corejs: "2",  
              targets: {
                  browsers: ['last 2 versions', 'ie &gt;= 9'],
              },
            }],
            '@babel/preset-react'
          ]
        }
      }
    ]
  },
  resolve: {
    extensions: ['.js', '.jsx']
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new htmlWebpackPlugin({
      template: './client/index.html',
      filename: 'index.html'
    })
  ]
}
</code></pre></div>
<h3 dir="auto">Error message</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/14016766/56009309-fc494c00-5d11-11e9-8445-94fa34d980d7.png"><img src="https://user-images.githubusercontent.com/14016766/56009309-fc494c00-5d11-11e9-8445-94fa34d980d7.png" alt="image" style="max-width: 100%;"></a></p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Babel version(s): 7.4.3</li>
<li>Node/npm version: [e.g. Node 10.15.3/npm 6.4.1]</li>
<li>OS: window 10</li>
</ul>
<h3 dir="auto">Rep</h3>
<p dir="auto"><a href="https://github.com/xuchenchenBoy/ssr">https://github.com/xuchenchenBoy/ssr</a> （Please execute npm run dev:server and release notes in server.js）</p>