Closed goldylucks closed 7 years ago
Could you confirm with webpack@2.2.0?
http://stackoverflow.com/questions/33683539/webpack-require-is-not-a-function-when-using-babel-6
In particular, the comment about Babel returning an Object when using require() with Babel 6.x
That said, with the number of fixes between beta.25 & 2.2.0, I would encourage you get get out of the beta releases sooner than later. Lots of Perf love in there as well.
npm start
on webpack 2.2.0
@abouthiroppy I'm still getting the same error on webpack@2.2.
@d3viant0ne did u change modules to false?
I read the SO thread before submitting this issue. Removing the require
s didn't resolve the issue
any other ideas?
Really wanna use tree shaking :)
I'll have some free time this afternoon, I'll dig around a bit and see what I can find.
When using .babelrc
and trying to specify modules:false
, I get an immediate error on import
being undefined, so I'm assuming the preset isn't taking at all.
.babelrc
"presets": [
["latest", {
"es2015": {
"modules": false
}
}], "stage-0", "react"
],
However, configuring the babel-loader in my wepback config works:
const jsLoader = {
test: /.js?$/,
use: [{
loader: 'babel-loader',
options: {
"babelrc": false,
"presets": [
["latest", {
"es2015": {
"modules": false
}
}], "stage-0", "react"
],
Also, specifying "babelrc": false,
reduces my bundles size. Lost on that one, since .bablerc
includes the same configuration as my webpack config.
Using:
webpack: 2.2.1
babel-loader: 6.2.10
Please include the full error message.
@loganfsmyth
/path-to-project/webpack.config.babel.js:1
(function (exports, require, module, __filename, __dirname) { import _extends from "babel-runtime/helpers/extends";
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:78:16)
at Module._compile (module.js:543:28)
at loader (/path-to-project/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/path-to-project/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at requireConfig (/path-to-project/node_modules/webpack/bin/convert-argv.js:96:18)
That error is from ES6 in your Webpack config, not from babel-loader
. The issue is that your .babelrc
says not to compile modules, but webpack.config.babel.js
runs in Node, not in the browser, so it does need modules compiled.
@loganfsmyth makes perfect sense! thanks for clarifying
Delete what isn't applicable below I'm submitting a bug report
Webpack Version: 2.x
Babel Core Version: 6.x
Babel Loader Version: 6.2.x
Please tell us about your environment: Linux, Ubuntu 16.04
Current behavior: ERROR in TypeError: __webpack_require__(...) is not a function
Expected/desired behavior: not crashing, and working with webpack 2 tree shaking :)
checking out this commit from my repo and running
npm start
The thing is I don't know what is causing the crash, because as u can c above, the logs are not very informational, hence I'm opening this issue and not asking on SO
webpack:
2.1.0-beta.25
webpack-dev-server:2.1.0-beta.0
it crashes on both webpack and dev server