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

I updated to Webpack 5, and "auto" appears in URL paths (so they don't work) #1588

Closed
trusktr opened this issue Jan 20, 2021 · 7 comments
Closed

Comments

@trusktr
Copy link

trusktr commented Jan 20, 2021

Current behaviour 💣

After updating to Webpack 5 (5.16), auto/ started appearing in my URL paths, so my <script> tags don't load.

Expected behaviour ☀️

Nothing breaks, things load like before.

Reproduction Example 👾

No reproduction, but this gave a hint: #1514

Environment 🖥

N/A

I solved my issue by setting output.publicPath to an empty string. It all works fine after that. But I don't think it should be required.

@jantimon
Copy link
Owner

jantimon commented Jan 20, 2021

Which html-webpack-plugin version did you use?

In the current 5.x branch it should be resolved: https://www.npmjs.com/package/html-webpack-plugin/v/5.0.0-beta.5

@serkanyersen
Copy link

I tried it on beta.6 it's still happening. just like op I had to set webpack's publicPath to empty string to prevent 'auto' to be put in the path.

@jantimon
Copy link
Owner

@trusktr @serkanyersen Thanks a lot for reporting this bug!

I would love to fix it however this codesandbox is using the following dependencies

    "html-webpack-plugin": "5.0.0-beta.6",
    "webpack": "5.16.0",
    "webpack-cli": "4.2.0",
    "webpack-dev-server": "3.11.2"

with the config

const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/template.ejs'
    })
  ]
};

and generates html without auto:

<!doctype html>
<html lang="en-us">
   <head>
      <meta charset="utf-8"/>
      <script defer="defer" src="main.js"></script>
   </head>
   <body>
      <div id="root" style="height: 100%"></div>
   </body>
</html>

So as you can see everything works correctly..

Please fork this sandbox and adjust it to reproduce the bug.
Otherwise I have no idea how I might help you.

@serkanyersen
Copy link

Thanks @jantimon I tried few things but could not replicate. it's possible that another plug-in I have is not compatible with wp5 and causing this problem. I'll investigate more and let you know if I find anything.

@jantimon
Copy link
Owner

Okay I'll close it for now please open a new bug ticket if you find out what's causing this strange behaviour

@trusktr
Copy link
Author

trusktr commented Feb 5, 2021

My reproduction webpack config is fairly minimal:

import {DefinePlugin, optimize} from 'webpack'
import * as path from 'path'
import * as HtmlWebpackPlugin from 'html-webpack-plugin'

const outputPath = `dist`
const nodeEnv = {
  // ...elided... don't think it matters
}

module.exports = {
  entry: './src/index.tsx',

  stats: {assets: false},

  output: {
    path: path.resolve(outputPath),
    filename: 'index.js',

    // The app won't load without this simple option. Webpack 5 issue: https://github.com/jantimon/html-webpack-plugin/issues/1588
    publicPath: '',
  },

  module: {
    rules: [
      {test: /\.js$/, use: ['source-map-loader'], enforce: 'pre'},

      {test: /\.ts$/, exclude: /node_modules/, use: [{loader: 'ts-loader', options: {transpileOnly: true}}]},

      {
        test: /\.tsx$/,
        exclude: /node_modules/,
        use: [{loader: 'babel-loader', options: {presets: ['@babel/preset-react']}}, {loader: 'ts-loader'}],
      },

      {test: /\.styl$/, use: ['style-loader', 'css-loader', {loader: 'stylus-loader', options: {}}]},

      {test: /\.css$/, use: ['style-loader', 'css-loader']},

      {test: /\.(jpg|svg|png|eot|ttf|woff|woff2)$/, exclude: [], use: [{loader: 'url-loader', options: {limit: -1}}]},
    ],
  },

  resolve: {
    extensions: ['.ts', '.tsx', '.js'],
    fallback: {
      fs: false,
      util: false,
      process: false,
    },
    alias: {
      '@material-ui/core': '@material-ui/core/es',
      '@material-ui/icons': '@material-ui/icons/es',
      '@material-ui/lab': '@material-ui/lab/es',
      '@material-ui/system': '@material-ui/system/es',
      '@material-ui/utils': '@material-ui/utils/es',

      // Prevent duplicates of @lume/element being included in the output bundle.
      '@lume/element': path.resolve('node_modules', '@lume', 'element'),
    },
  },

  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',
      hash: true,
    }),

    // ENV
    new DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(nodeEnv),

      ...{
        process: 'undefined',
        'process.env': '({})',
        'process.argv': '([])',
        'process.stdout': false,
        'process.platform': JSON.stringify(process.platform),
      },

      'process.browser': 'true',
    }),
    new optimize.ModuleConcatenationPlugin(),
  ],

  devServer: {
    contentBase: outputPath,
    host: 'localhost',
    port: 8090,
    hot: false,
  },
}

Versions:

    "webpack": "^5.16.0",
    "webpack-cli": "^4.5.0",
    "webpack-dev-server": "^3.11.2"
    "babel-loader": "^8.1.0",
    "css-loader": "^1.0.0",
    "file-loader": "^6.2.0",
    "source-map-loader": "^0.2.4",
    "style-loader": "^0.21.0",
    "stylus-loader": "^3.0.2",
    "ts-loader": "^4.4.2",
    "url-loader": "^4.1.1",

@jantimon
Copy link
Owner

jantimon commented Feb 5, 2021

are all those alias and loader configurations necessary to reproduce the issue?

which html-webpack-plugin version are you using?

if you want me to spent my spare time for your please provide at least a reproduction example based on https://codesandbox.io/s/html-webpack-plugin-5x-alpha-d37s2 :)

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

3 participants