Skip to content

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

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

Open
kimulaco opened this issue Apr 16, 2020 · 4 comments

Comments

@kimulaco
Copy link

kimulaco commented Apr 16, 2020

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

@bananacoffee
Copy link

I have a same probrem.

This is due to this commit.
mde/ejs@12beb5c

Please remove to return deps like my pullrequest.

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

@flurin
Copy link

flurin commented Jun 5, 2020

Same issue here.

@saeedahadian
Copy link

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

@bananacoffee
Copy link

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

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

4 participants