为了账号安全,请及时绑定邮箱和手机立即绑定

写的htmlWebpackPlugin获取它的options和files打包一直出错

indexhtml:

<!DOCTYPE html>

<html>

    <head>

        <meta charset="UTF-8">

        <title><%= htmlWebpackPlugin.options.title %></title>

    </head>

    <body>

        <%= htmlWebpackPlugin.options.date%>

        <% for( var key in htmlWebpackPlugin){%><%= key%><%= }%>

        <% for( var key in htmlWebpackPlugin.files){%><%= key%>:<%= JSON.stringify(htmlWebpackPlugin.files[key])%><%= }%>

    </body>



打包时候一直提示“ERROR in Template execution failed: TypeError: Cannot read property 'files' of undefined ”



打包后的index.html文件内容:

Html Webpack Plugin:

<pre>

  TypeError: Cannot read property 'files' of undefined

  

  - index.html:91 

    /Users/carol/www/webpackDemo/index.html:91:43

  

  - index.html:104 module.exports

    /Users/carol/www/webpackDemo/index.html:104:3

  

  - index.js:264 

    [webpackDemo]/[html-webpack-plugin]/index.js:264:16

  

  - util.js:16 tryCatcher

    [webpackDemo]/[bluebird]/js/release/util.js:16:23

  

  - promise.js:512 Promise._settlePromiseFromHandler

    [webpackDemo]/[bluebird]/js/release/promise.js:512:31

  

  - promise.js:569 Promise._settlePromise

    [webpackDemo]/[bluebird]/js/release/promise.js:569:18

  

  - promise.js:606 Promise._settlePromiseCtx

    [webpackDemo]/[bluebird]/js/release/promise.js:606:10

  

  - async.js:138 Async._drainQueue

    [webpackDemo]/[bluebird]/js/release/async.js:138:12

  

  - async.js:143 Async._drainQueues

    [webpackDemo]/[bluebird]/js/release/async.js:143:10

  

  - async.js:17 Immediate.Async.drainQueues

    [webpackDemo]/[bluebird]/js/release/async.js:17:14

  

</pre>

在terminal中出现的错误提示:

Hash: f31b61d7e4a63d32cf9d

Version: webpack 3.6.0

Time: 590ms

                             Asset     Size  Chunks             Chunk Names

./js/main--aea7fcede5dd435d3e28.js  2.51 kB       0  [emitted]  main

   ./js/a--36facad12b17b00910bb.js  2.52 kB       1  [emitted]  a

                        index.html  1.02 kB          [emitted]  

   [0] ./src/script/main.js 21 bytes {0} [built]

   [1] ./src/script/a.js 22 bytes {1} [built]


ERROR in Template execution failed: TypeError: Cannot read property 'files' of undefined


ERROR in   TypeError: Cannot read property 'files' of undefined

  

  - index.html:91 

    /Users/carol/www/webpackDemo/index.html:91:43

  

  - index.html:104 module.exports

    /Users/carol/www/webpackDemo/index.html:104:3

  

  - index.js:264 

    [webpackDemo]/[html-webpack-plugin]/index.js:264:16

  

  - util.js:16 tryCatcher

    [webpackDemo]/[bluebird]/js/release/util.js:16:23

  

  - promise.js:512 Promise._settlePromiseFromHandler

    [webpackDemo]/[bluebird]/js/release/promise.js:512:31

  

  - promise.js:569 Promise._settlePromise

    [webpackDemo]/[bluebird]/js/release/promise.js:569:18

  

  - promise.js:606 Promise._settlePromiseCtx

    [webpackDemo]/[bluebird]/js/release/promise.js:606:10

  

  - async.js:138 Async._drainQueue

    [webpackDemo]/[bluebird]/js/release/async.js:138:12

  

  - async.js:143 Async._drainQueues

    [webpackDemo]/[bluebird]/js/release/async.js:143:10

  

  - async.js:17 Immediate.Async.drainQueues

    [webpackDemo]/[bluebird]/js/release/async.js:17:14

  


Child html-webpack-plugin for "index.html":

     1 asset

       [0] ./node_modules/html-webpack-plugin/lib/loader.js!./index.html 1.49 kB {0} [built]

       [2] (webpack)/buildin/global.js 509 bytes {0} [built]

       [3] (webpack)/buildin/module.js 517 bytes {0} [built]

        + 1 hidden module


正在回答

2 回答

<% for( var key in htmlWebpackPlugin){%><%= key%><%= }%>中最后的<%= }%>等号不要

0 回复 有任何疑惑可以回复我~

打包后的index.html文件内容:

Html Webpack Plugin:

<pre>

  TypeError: Cannot read property 'files' of undefined

  

  - index.html:91 

    /Users/carol/www/webpackDemo/index.html:91:43

  

  - index.html:104 module.exports

    /Users/carol/www/webpackDemo/index.html:104:3

  

  - index.js:264 

    [webpackDemo]/[html-webpack-plugin]/index.js:264:16

  

  - util.js:16 tryCatcher

    [webpackDemo]/[bluebird]/js/release/util.js:16:23

  

  - promise.js:512 Promise._settlePromiseFromHandler

    [webpackDemo]/[bluebird]/js/release/promise.js:512:31

  

  - promise.js:569 Promise._settlePromise

    [webpackDemo]/[bluebird]/js/release/promise.js:569:18

  

  - promise.js:606 Promise._settlePromiseCtx

    [webpackDemo]/[bluebird]/js/release/promise.js:606:10

  

  - async.js:138 Async._drainQueue

    [webpackDemo]/[bluebird]/js/release/async.js:138:12

  

  - async.js:143 Async._drainQueues

    [webpackDemo]/[bluebird]/js/release/async.js:143:10

  

  - async.js:17 Immediate.Async.drainQueues

    [webpackDemo]/[bluebird]/js/release/async.js:17:14

  

</pre>

在terminal中出现的错误提示:

Hash: f31b61d7e4a63d32cf9d

Version: webpack 3.6.0

Time: 590ms

                             Asset     Size  Chunks             Chunk Names

./js/main--aea7fcede5dd435d3e28.js  2.51 kB       0  [emitted]  main

   ./js/a--36facad12b17b00910bb.js  2.52 kB       1  [emitted]  a

                        index.html  1.02 kB          [emitted]  

   [0] ./src/script/main.js 21 bytes {0} [built]

   [1] ./src/script/a.js 22 bytes {1} [built]


ERROR in Template execution failed: TypeError: Cannot read property 'files' of undefined


ERROR in   TypeError: Cannot read property 'files' of undefined

  

  - index.html:91 

    /Users/carol/www/webpackDemo/index.html:91:43

  

  - index.html:104 module.exports

    /Users/carol/www/webpackDemo/index.html:104:3

  

  - index.js:264 

    [webpackDemo]/[html-webpack-plugin]/index.js:264:16

  

  - util.js:16 tryCatcher

    [webpackDemo]/[bluebird]/js/release/util.js:16:23

  

  - promise.js:512 Promise._settlePromiseFromHandler

    [webpackDemo]/[bluebird]/js/release/promise.js:512:31

  

  - promise.js:569 Promise._settlePromise

    [webpackDemo]/[bluebird]/js/release/promise.js:569:18

  

  - promise.js:606 Promise._settlePromiseCtx

    [webpackDemo]/[bluebird]/js/release/promise.js:606:10

  

  - async.js:138 Async._drainQueue

    [webpackDemo]/[bluebird]/js/release/async.js:138:12

  

  - async.js:143 Async._drainQueues

    [webpackDemo]/[bluebird]/js/release/async.js:143:10

  

  - async.js:17 Immediate.Async.drainQueues

    [webpackDemo]/[bluebird]/js/release/async.js:17:14

  


Child html-webpack-plugin for "index.html":

     1 asset

       [0] ./node_modules/html-webpack-plugin/lib/loader.js!./index.html 1.49 kB {0} [built]

       [2] (webpack)/buildin/global.js 509 bytes {0} [built]

       [3] (webpack)/buildin/module.js 517 bytes {0} [built]

        + 1 hidden module


0 回复 有任何疑惑可以回复我~
#1

w2458452805

跟你一样的问题,请问解决了吗?
2017-11-23 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

写的htmlWebpackPlugin获取它的options和files打包一直出错

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信