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

templateParameters. Parameter is not defined #915

Closed
dfvgbh opened this issue Mar 28, 2018 · 4 comments
Closed

templateParameters. Parameter is not defined #915

dfvgbh opened this issue Mar 28, 2018 · 4 comments

Comments

@dfvgbh
Copy link

dfvgbh commented Mar 28, 2018

Prerequisites

node: 8.10.0
webpack: 4.3.0
html-webpack-plugin: 3.1.0

Description

Using templateParameters option gets next error:

Error Message & Stack Trace

Html Webpack Plugin:

  ReferenceError: foo is not defined
  
  - loader.js:4 eval
    [index.html?.]/[html-webpack-plugin]/lib/loader.js:4:11
  
  - loader.js:7 module.exports
    [index.html?.]/[html-webpack-plugin]/lib/loader.js:7:3
  
  - index.js:282 Promise.resolve.then
    [webpack]/[html-webpack-plugin]/index.js:282:18
  
  
  - next_tick.js:188 process._tickCallback
    internal/process/next_tick.js:188:7
  

Config

webpack.config.js

const HtmlWebPackPlugin = require('html-webpack-plugin');

module.exports = {
  plugins: [
    new HtmlWebPackPlugin({
      template: 'src/index.html',
      templateParameters: {
        foo: 'bar'
      }
    })
  ]
};

src/index.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible"
          content="ie=edge">
</head>
<body>
    <h1><%= foo %></h1>
</body>
</html>
@jantimon
Copy link
Owner

Thank you for the feedback - will look into that.
Did you already have time to debug it a little bit?

@jantimon
Copy link
Owner

Oh thanks a lot @dfvgbh the reason is here in the hardcoded variables section:

const templateVariables = [
'compilation',
'webpack',
'webpackConfig',
'htmlWebpackPlugin'
];

Any ideas how we could improve that?

@jantimon
Copy link
Owner

jantimon commented Apr 3, 2018

Fixed in 3.2

@lock
Copy link

lock bot commented May 31, 2018

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants