Git Product home page Git Product logo

Comments (8)

AndrewRayCode avatar AndrewRayCode commented on June 2, 2024

I lied, this error is coming from the rewire plugin, not this plugin

from babel-plugin-rewire.

AndrewRayCode avatar AndrewRayCode commented on June 2, 2024

Well, I lied again. this error only seems to happen if I include this plugin. Still investigating...

from babel-plugin-rewire.

speedskater avatar speedskater commented on June 2, 2024

Might it be possible that you are using rewire.js along babel-plugin-rewire? If this is the case can you check whether the error remains if you change babel-loader?plugins=rewire&optional=runtime to
babel-lodaer?plugins=babel-plugin-rewire

from babel-plugin-rewire.

AndrewRayCode avatar AndrewRayCode commented on June 2, 2024

I changed it to loader: 'babel-loader?plugins=babel-plugin-rewire'. Webpack gives the warning (followed by lots of errors in rewire):

WARNING in ./~/rewire/lib/moduleEnv.js
require.extensions is not supported by webpack. Use a loader instead.

What do you mean using rewire.js along with the plugin? We do this in plenty of places in the code:

let rewire = require('rewire');

Sorry for my density - I'm not familiar with the internals of rewire - I assumed this plugin did some magic to allow require('rewire') to still work. Is that not the case? Looking at the readme it appears that the API is automatically injected into all classes that are imported? Is that correct?

from babel-plugin-rewire.

AndrewRayCode avatar AndrewRayCode commented on June 2, 2024

Tested in a blank project, simply adding this line:

var rewire = require('rewire');

Triggers the errors/warnings:

WARNING in ./~/rewire/lib/moduleEnv.js
require.extensions is not supported by webpack. Use a loader instead.

WARNING in ./~/rewire/lib/moduleEnv.js
Module not found: Error: Cannot resolve module 'coffee-script' in node_modules/rewire/lib
@ ./~/rewire/lib/moduleEnv.js 103:13-37

ERROR in ./~/rewire/lib/rewire.js
Module not found: Error: Cannot resolve module 'module' in node_modules/rewire/lib
@ ./~/rewire/lib/rewire.js 22:13-30

However, if I add this to the webpack config in the blank project:

var RewirePlugin          = require("rewire-webpack");
....
plugins: [
      new RewirePlugin()
]

Then the bundle is valid. More investigation required...

from babel-plugin-rewire.

AndrewRayCode avatar AndrewRayCode commented on June 2, 2024

Something is conflicting somewhere with babel and rewire. In the large project, what's getting built to the bundle is:

exports['default'] = _Object$assign(var MyReactClass = (function (_React$Component) {

which throws the error Unexpected token var in the webpack build step. It looks like turning ES6>ES3 is getting wrapped in a rewire statement, but the syntax produced is wrong. I cannot yet reproduce this in small test project

from babel-plugin-rewire.

speedskater avatar speedskater commented on June 2, 2024

Have you tried the latest version (0.1.3) of babel-plugin-rewire this should fix the problem with the wrapping of the default export

from babel-plugin-rewire.

AndrewRayCode avatar AndrewRayCode commented on June 2, 2024

Phew, ok, looks like using the explicit name and the newest version works.

from babel-plugin-rewire.

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.