Git Product home page Git Product logo

Comments (4)

jdalton avatar jdalton commented on May 25, 2024

Hi @usman-subhani!

Can you post what the transpiled code looks like?

from babel-plugin-lodash.

usman-subhani avatar usman-subhani commented on May 25, 2024

Hey @jdalton, sure. This is the transpiled code with the plugin

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "test", function() { return test; });
class test {
  constructor() {
    this._ = undefined; // lodash is replaced with 'undefined' here
  }

  someMethod() {
    const value = this._.get({
      a: 1
    }, 'a'); // error thrown here because this._ is undefined

  }

}

and this is the code after removing the plugin

/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "test", function() { return test; });
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "./node_modules/lodash/lodash.js");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);

class test {
  constructor() {
    this._ = lodash__WEBPACK_IMPORTED_MODULE_0___default.a; // lodash is imported and set here
  }

  someMethod() {
    const value = this._.get({
      a: 1
    }, 'a'); // works fine now

  }

}

This is the .babelrc config

{
  "presets": [
    "@babel/preset-react",
    ["@babel/preset-env", {
      "targets": {
        "chrome": "72",
        "firefox": "64",
        "opera": "50",
        "node": "current"
      }
    }]
  ],
  "plugins": ["lodash", "@babel/plugin-transform-runtime"]
}

I have v3.3.4 of babel-plugin lodash

from babel-plugin-lodash.

drudv avatar drudv commented on May 25, 2024

Have the same issue: lodash is being replaced with undefined. If I disable babel-plugin-lodash, the reference is preserved.

from babel-plugin-lodash.

JackieCheung avatar JackieCheung commented on May 25, 2024

Have the same issue: lodash is being replaced with undefined. If I disable babel-plugin-lodash, the reference is preserved.

same issue, is there a solution now?

from babel-plugin-lodash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.