ERROR in http.min.js from Terser

Open
#7 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
build-system

Research direction

Start with http.js and webpack.build-lib.js, then run the production build that uses mode: 'production' and Terser; compare it with the development build. Trace how the ReplacePlugin output reaches lib/http.min.js and determine why the export is no longer at the top level. Done means the production build completes without the reported Terser error.

Written by the indexing model from the issue text.

Description

When I set webpack config mode: 'production',it throw error:

ERROR in http.min.js from Terser
"Export" statement may only appear at the top level [http.min.js:1161,0]

But when I set mode: 'development',it works...I can't figure out why.

// http.js

const http = () => {}

http.version = '__version__';

export default http;
// webpack.build-lib.js
const path = require('path');
const ReplacePlugin = require('../lib/webpack-plugin-replace');
const rootPath = path.resolve(__dirname, '..');
const pkg = require('../package.json');

const libName = 'http';
const entryFile = path.resolve(rootPath, `src/${libName}.js`);

module.exports = {
  entry: entryFile,
  mode: 'production',
  output: {
    path: path.resolve(rootPath, 'lib'),
    filename: `${libName}.min.js`,
    libraryTarget: 'umd2',
    libraryExport: 'default',
  },
  plugins: [
    new ReplacePlugin({
      exclude: [
        /node_modules/,
      ],
      patterns: [{
        regex: /__version__/g,
        value: pkg.version,
      }],
    }),
  ],
};

Dominant language
JavaScript
Stars
36
Forks
8
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lukeed/webpack-plugin-replace

All issues in lukeed/webpack-plugin-replace

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.