mcmath / ejs-html-loader

Webpack loader for rendering HTML from EJS templates
MIT License
47 stars 9 forks source link

I fail build with error "Cannot read property 'forEach' of undefined" in ejs@3.0.2. #19

Open kimulaco opened 4 years ago

kimulaco commented 4 years ago

Overview

ejs@3 fails to build with the error "Cannot read property 'forEach' of undefined". The repository is here.

No error occurs when using ejs@2.7.4. (The example is here)

Package Version

webpack.config.js

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  mode: process.env.NODE_ENV || 'development',
  entry: {
    index: path.resolve(process.cwd(), './src/ejs/index.ejs')
  },
  output : {
    filename: '[name].html',
    path: path.resolve(process.cwd(), './dist')
  },
  module: {
    rules: [
      {
        test: /\.ejs$/,
        use: [
          'html-loader',
          {
            loader: 'ejs-html-loader',
            options: {
              title: 'ejs-html-loader Example'
            }
          }
        ]
      }
    ]
  },
  plugins : [
    new HtmlWebpackPlugin({
      filename : 'index.html',
      template : path.resolve(process.cwd(), './src/ejs/index.ejs')
    })
  ]
}

Error

yarn build
yarn run v1.17.3
$ NODE_ENV=production webpack
Hash: a9250b2383821e3dda42
Version: webpack 4.42.1
Time: 283ms
Built at: 2020-04-16 1:50:55 PM
 1 asset
Entrypoint index = index.html
[0] ./src/ejs/index.ejs 58 bytes {0} [built] [1 error]

ERROR in ./src/ejs/index.ejs
Module Error (from ./node_modules/ejs-html-loader/lib/index.js):
(Emitted value instead of an instance of Error) ejs-html-loader
Cannot read property 'forEach' of undefined
Child HtmlWebpackCompiler:
     1 asset
    Entrypoint HtmlWebpackPlugin_0 = __child-HtmlWebpackPlugin_0
    [0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/ejs/index.ejs 58 bytes {0} [built] [1 error]

    ERROR in ./src/ejs/index.ejs (./node_modules/html-webpack-plugin/lib/loader.js!./src/ejs/index.ejs)
    Module Error (from ./node_modules/ejs-html-loader/lib/index.js):
    (Emitted value instead of an instance of Error) ejs-html-loader
    Cannot read property 'forEach' of undefined
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected cause

Maybe the return value of the compile function has changed from ejs@3 and deps is no array.

https://github.com/mcmath/ejs-html-loader/blob/master/src/render.js#L9

bananacoffee commented 4 years ago

I have a same probrem.

This is due to this commit. https://github.com/mde/ejs/commit/12beb5ccc08ac1fc5240128f7d5dba2e82acf57f

Please remove to return deps like my pullrequest.

(I'm sorry, my English is not good.)

flurin commented 4 years ago

Same issue here.

saeedahadian commented 4 years ago

This issue is not resolved yet. Please take a look at it.

bananacoffee commented 3 years ago

I have fixed it in my repository. https://github.com/bananacoffee/ejs-html-loader