Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: global is not defined #8

Closed
richardscarrott opened this issue Jan 13, 2015 · 3 comments
Closed

Uncaught ReferenceError: global is not defined #8

richardscarrott opened this issue Jan 13, 2015 · 3 comments

Comments

@richardscarrott
Copy link

I'm using the expose loader like this:

var React = require('expose?React!react');

With the following webpack.config:

module.exports = {
    entry: 'app.js',
    output: {
        path: path.join(__dirname, 'dist/www'),
        filename: '[chunkhash].entry.js',
        chunkFilename: '[chunkhash].[name].js'
    },
    module: {
        noParse: /bower_components/,
        loaders: [
            // { test: require.resolve('react'), loader: 'expose?React' },
            { test: /\.js$/, loader: 'jsx-loader?harmony' },
            { test: /\.css$/, loader: 'style-loader!css-loader' },
            { test: /\.(png|jpg|gif)$/, loader: 'url-loader?limit=8192' }
        ]
    },
    resolve: {
        root: [
            path.join(__dirname, 'www/bower_components'),
            path.join(__dirname, 'www/app'),
            path.join(__dirname, 'www/assets')
        ]
    },
    plugins: [
        new webpack.ResolverPlugin(
            new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('bower.json', ['main'])
        ),
        new StatsPlugin(path.join(__dirname, 'dist/server', 'stats.json'), {
            chunkModules: true
        })
    ]
};

The module compiles down to:

module.exports = global["React"] = require("-!/Users/Rich/Projects/react-webpack-boilerplate/node_modules/jsx-loader/index.js?harmony!/Users/Rich/Projects/react-webpack-boilerplate/www/bower_components/react/react.js");

so even if I change global to window it'll error out on the require call.

What I imagine it should compile down to is:

module.exports = window["React"] = __webpack_require__(10); // or whatever the react id is.

I'm struggling to work out how I'd achieve this or what I'm doing wrong, any ideas?

@richardscarrott
Copy link
Author

Might be worth noting I also get a similar problem when using the import loader:

var Router = require('imports?React=react!react-router'); // Uncaught ReferenceError: require is not defined

because it compiles down to:

/*** IMPORTS FROM imports-loader ***/
var React = require("react");

@richardscarrott
Copy link
Author

I've found the problem, it's because of noParse: /bower_components/ which prevented the loader output from being being transpiled...

@AndyOGo
Copy link

AndyOGo commented Dec 15, 2017

@richardscarrott
Thanks you very much for posting you solution, it worked for me.

@sokra
@d3viant0ne
Could please add this to the readme as a caveat, saying that this loader will of course not work if the module is excluded by noParse option (which is not ideal btw.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants