Comments (8)
I lied, this error is coming from the rewire plugin, not this plugin
from babel-plugin-rewire.
Well, I lied again. this error only seems to happen if I include this plugin. Still investigating...
from babel-plugin-rewire.
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.
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.
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.
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.
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.
Phew, ok, looks like using the explicit name and the newest version works.
from babel-plugin-rewire.
Related Issues (20)
- Broken bundles after upgrade to 1.2.0 HOT 1
- Error with `babel/preset-typescript` HOT 4
- How can I enable this for one module only? HOT 1
- Simply including this breaks lots of things
- Not working with jest, Invalid variable access: _get__ HOT 6
- Thanks for a great plugin! I'd suggest adding dynamic import syntax to the readme! :) HOT 2
- Windows 10 and Ubuntu output different code HOT 2
- can not work with element-ui
- Webpack bundle size increases dramatically with rewire HOT 1
- babel/plugin-transform-typescript and rewire HOT 1
- Documentation clarification
- Documentation clarification
- Documentation clarification HOT 1
- rewire seems to break `import * as foo from 'module'` HOT 1
- property names as variable names don't work in babel-plugin-rewire
- __Rewire__ is not a function HOT 1
- babel-plugin-rewire does not work in a Typescript project HOT 5
- Maintenance Request, is this repo actively maintained?
- Any plan to port this plugin to SWC?
- Integration with CRACO HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-plugin-rewire.