webpack-contrib / webpack-bundle-analyzer

Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap
MIT License
12.59k stars 488 forks source link

Error generating bundle report: Error parsing bundle asset: 'import' and 'export' may appear only with 'sourceType: module' #556

Closed eamodio closed 1 year ago

eamodio commented 1 year ago

Issue description

When using the analyzer to generate a report, some of my entry points work, but others report the following errors:

Error parsing bundle asset:  'import' and 'export' may appear only with 'sourceType: module'```

#### Technical info

<!--
Please include the output of running the command below:

npx envinfo --system --binaries --npmPackages='*webpack*' --npmGlobalPackages=webpack-bundle-analyzer 

-->

<pre>
  System:
    OS: Windows 10 10.0.22623
    CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
    Memory: 14.23 GB / 31.92 GB
  Binaries:
    Node: 18.14.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.3.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    clean-webpack-plugin: 4.0.0 => 4.0.0
    copy-webpack-plugin: 11.0.0 => 11.0.0
    csp-html-webpack-plugin: 5.1.0 => 5.1.0
    css-minimizer-webpack-plugin: 4.2.2 => 4.2.2
    fork-ts-checker-webpack-plugin: 6.5.2 => 6.5.2
    html-webpack-plugin: 5.5.0 => 5.5.0
    image-minimizer-webpack-plugin: 3.8.1 => 3.8.1
    terser-webpack-plugin: 5.3.6 => 5.3.6
    webpack: 5.75.0 => 5.75.0
    webpack-bundle-analyzer: 4.8.0 => 4.8.0
    webpack-cli: 5.0.1 => 5.0.1
    webpack-node-externals: 3.0.0 => 3.0.0
    webpack-require-from: 1.8.6 => 1.8.6
</pre>

#### Debug info
```js
new BundleAnalyzerPlugin({
    analyzerMode: 'static',
    generateStatsFile: true,
    openAnalyzer: false,
    reportFilename: path.join(out, 'webview-bundle-report.html'),
    statsFilename: path.join(out, 'stats.json'),
})

What other Webpack plugins were used? Many: My webpack.config.js can be found here: https://github.com/gitkraken/vscode-gitlens/blob/daa99a8c6d0557990ec6035f388c0f3458ac35db/webpack.config.js

stats.zip

valscion commented 1 year ago

Ah I see you have

        output: {
            chunkFilename: 'feature-[name].js',
            filename: '[name].js',
            libraryTarget: 'module',
            path: path.join(__dirname, 'dist', 'webviews'),
            publicPath: '#{root}/dist/webviews/',
        },
        experiments: {
            outputModule: true,
        },

in your webpack config, so this issue might be a duplicate of https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/427