Bug
Bundle is incorrect and crashes with “exports is not defined”.
Unfortunately I can’t share steps to reproduce, as the codebase is closed source. However, it definitely worked with 2.2.0-rc.4, so it must be a recent change.
Bundle should be correct and not crash.
Webpack: 2.2.0-rc.5
I still get this with
2.2.0
(no-rc
suffixes). not sure how to help.It seems that I get it when I try to import anything from
api/index.js
file, which looks like this:@indeyets are you using
babel-loader
withes2015
preset? I think I was running into the same issue as you. I had to change"modules": false
to"modules": "umd"
to get my project working again. I don’t think this is right though.For anyone running into this issue, I got my build working with these
babel-loader
options:Also just delete your
.babelrc
file, it was interfering in my build. Configure babel from your webpack config.You really want
"modules": false
because you don’t get tree shaking when you use"modules": "umd"
Using version 2.2.1 and getting the same problem.
Using version 2.2.1 and getting the same problem(“ReferenceError exports is not defined”).
For me removing
target: "node"
in my dev webpack config solved the issue.I’ve tried all of the options in this thread, and nothing is working for me. Still getting
ReferenceError: exports is not defined
.If I add
import 'babel-polyfill'
to the top of my file, I get this error in the browser:If I add the
transform-runtime
plugin to my.babelrc
, I get this crash when I’m compiling:For anyone using TypeScript and babel, if you still face this issue:
In your tsconfig.json:
Make sure you have this:
I have accidentally put
module: "commonjs"
and that was causing this error.In your .babelrc:
Make sure you have set modules to false and loose to true:
I can consistently reproduce this in CRA codebase:
Then edit
packages/react-scripts/template/src/App.js
to have an empty block in therender
method:Press save. The browser will reload.
Then edit it to remove the empty block and press save.
You will see the error:
Unfortunately some internal state appears corrupted because even if I refresh the page, I keep getting the broken bundle. It only gets fixed by a restart of the server.
This is a pretty critical issue for us, as we were planning to cut the release including Webpack 2 this week.
Still occurs with webpack 3.
It seems like it depends on your babel plugins.
.babelrc ->change false to “commonjs”,then i solve it.
{
“presets”: [
[“env”, {
“modules”: “commonjs”
}],
“stage-2”
],
“plugins”: [“transform-runtime”],
“comments”: false,
“env”: {
“test”: {
“presets”: [“env”, “stage-2”],
“plugins”: [“transform-es2015-modules-commonjs”, “dynamic-import-node”]
}
}
}
A solution for me anyway was change babel-loader config, under plugins,
['transform-runtime', { "polyfill": false }]
All the same even with webpack@3. Helps only
plugins: [ ['transform-runtime', { "polyfill": false }] ]
in babel config.If polyfill is needed, it’s possible to install
babel-polifyll
pkg separately and explicitly import it in app.I had the same issue in a Vue CLI project.
What a Heisenbug.
The issue went away when I (in a bout of frustration) deleted by
.babelrc
and restoredbabel.config.json
to the default settings.Is anyone else out there as confused about Babel (and Webpack) as I am?
any progress on this issue?