question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught ReferenceError: exports is not defined

See original GitHub issue

💬 Questions and Help

Hi, when I try to print out the extracted scripts(getScriptTags) on the server i receive those errors in the console : Uncaught ReferenceError: exports is not defined

The code in those files starts with :

exports.ids = ["components-Home"];
exports.modules = {

My webpack config on the server looks like this :

...
module.exports = {
  devtool: isDev ? 'inline-source-map' : false,
  entry: [
    './server/index.js'
  ],
  externals: [],
  target: 'node',
  output: {
    path: path.join(__dirname, outputDirectory),
    filename: 'bundle.js',
    publicPath: '/',
  },
  mode: isDev ? 'development' : 'production',
  resolve: {
    extensions: [".js", ".jsx", ".json"]
  },
  plugins: [
    new CleanWebpackPlugin(outputDirectory),
    new LoadablePlugin(),
  ],
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        },
      },
      {
        test: /\.jsx$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        }
      },
      {
        test: /\.css$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              publicPath: '../'
            }
          },
          "css-loader"
        ]
      },
      {
        test: /\.(png|woff|woff2|eot|ttf|svg)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 8192,
              name: 'static/[hash]-[name].[ext]',
              publicPath: '../'
            }
          }
        ]
      }
    ]
  }
}

if(isDev) {
  module.exports.entry.push('webpack/hot/poll?1000')
  module.exports.externals.push(nodeExternals({ whitelist: ['webpack/hot/poll?1000'] }))
  module.exports.plugins.push(
    new webpack.NamedModulesPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
    new WebpackShellPlugin({
      onBuildStart:['echo "Webpack Start"'], 
      onBuildEnd:['node ' + path.join(__dirname, outputDirectory) + '/' + 'bundle.js']
    }),
  )
} else {
  module.exports.externals.push(nodeExternals())
}

Anyone knows whats going on here ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rajocularcommented, Nov 26, 2020

@ischoe I’m running into this same issue, can you share the changes you made in your Webpack config?

1reaction
jeroenkampingacommented, Nov 13, 2020

Hi @ischoe I have the same issue. Can you tell me what you’ve changed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript ReferenceError: exports is not defined
Trying to implement a module following the official handbook, I get this error message: Uncaught ReferenceError: exports ...
Read more >
How to fix ReferenceError: exports is not defined TypeScript
If you are getting the error for code that runs in the browser, try defining a global exports variable above the script tags...
Read more >
Uncaught ReferenceError: exports is not defined : r/typescript
Getting this error for some dumb reason i'm sure. Uncaught ReferenceError: exports is not defined. at app.js:2. (anonymous) @ app.js:2. all ...
Read more >
exports is not defined" in browser : WEB-26773
Typescript compiler outputs wrong javascript module format, giving "ReferenceError: exports is not defined" in browser ; "use strict"; Object.defineProperty ...
Read more >
visual studio typescript "Uncaught ReferenceError: exports is ...
HTML : visual studio typescript " Uncaught ReferenceError: exports is not defined at.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found