Giter VIP home page Giter VIP logo

Comments (8)

miquelmasrieramrf avatar miquelmasrieramrf commented on May 30, 2024 13

that would be nice!
In the meantime if you want to use inject-loader with babel7, you can use @babel/plugin-transform-modules-commonjs.
It will transform the modules to commonjs so the loader will work

from inject-loader.

plasticine avatar plasticine commented on May 30, 2024 11

@matteoantoci Hey thanks for the report, I’ll try and find time to have a look :)

from inject-loader.

seanparmelee avatar seanparmelee commented on May 30, 2024 4

I opened a couple PRs that should help out here:
#73 adds ESM support so you no longer have to transform your modules to CJS format before running them through inject-loader
#74 includes #73 and upgrades to Babel 7.

Would love it if someone could try out the ESM feature in either PR to help identify any use cases I may have missed.

from inject-loader.

wwarme avatar wwarme commented on May 30, 2024

Had the very same issue, we just migrated to Babel 7, @babel/plugin-transform-modules-commonjs came to rescue. Thanks alot!
If not dependant on module: "esnext" - module: "commonjs" in tsconfig does the trick too.

from inject-loader.

plasticine avatar plasticine commented on May 30, 2024

Thanks tl;dr of this is that inject-loader operates on CJS modules only (at the moment anyway), so any code you want to inject needs to be compiled to CJS before inject-loader can operate on it. This should probably be documented better and/or an example for Babel 7.

from inject-loader.

miquelmasrieramrf avatar miquelmasrieramrf commented on May 30, 2024

🎉 babel 7.5

https://babeljs.io/blog/2019/07/03/7.5.0#dynamic-import-9552-https-githubcom-babel-babel-pull-9552-and-10109-https-githubcom-babel-babel-pull-10109

babel/babel#9552

from inject-loader.

zfeher avatar zfeher commented on May 30, 2024

Hey' We are currently migrating to Babel 7.5.5 and Webpack 4.35.3 and we ran into some problem with some of our tests which needs inject-loader.

As soon as I add the import SomeComponent from 'inject-loader!.'; and run the tests it will print an error that it doesn't know about the object rest/spread operator (whereas babel preset env is properly configured and set to the correct node version).

Compiling the same file via babel cli works without an error. It seems that the babel configuration is not used by inject loader. (the same setup works with Babel 6 with Webpack 3)

I've tried to explicitly add the @babel/plugin-proposal-object-rest-spread plugin as well without any success. Also tried to add babel as an inline loader like babel-loader!inject-loader!. / !inject-loader!babel-loader!.

Is there a workaround for this for now?
When can we expect Babel 7 support?

from inject-loader.

amccloud avatar amccloud commented on May 30, 2024

I was able to work around this issue by upgrading inject-loader to @seanparmelee's babel 7 fork seanparmelee@fcd20ba at and then setting babel-preset-env's modules to commonjs for my test env

{
  "env": {
    "test": {
      "presets": [
        [
          "@babel/preset-env",
          {
            "modules": "commonjs"
          }
        ]
      ]
   }
}

from inject-loader.

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.