ejs-html-loader icon indicating copy to clipboard operation
ejs-html-loader copied to clipboard

I fail build with error "Cannot read property 'forEach' of undefined" in [email protected].

Open kimulaco opened this issue 4 years ago • 4 comments

Overview

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

No error occurs when using [email protected]. (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

kimulaco avatar Apr 16 '20 05:04 kimulaco

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.)

bananacoffee avatar Jun 03 '20 07:06 bananacoffee

Same issue here.

flurin avatar Jun 05 '20 07:06 flurin

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

saeedahadian avatar Jun 22 '20 10:06 saeedahadian

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

bananacoffee avatar Jan 29 '21 11:01 bananacoffee