Html-webpack-plugin: Cannot resolve 'file' or 'directory'

Created on 11 Mar 2016  路  4Comments  路  Source: jantimon/html-webpack-plugin

Hi!
Could you help me please with this question, I cannot understand what's wrong.

File webpack.config.js is located in the root project folder. But I want to move this file to scripts folder. Here is a part of my Webpack config:

  plugins: [
    new HtmlWebpackPlugin({
      template: 'components/index.tpl.html',
      inject: 'body',
      filename: 'index.html'
    }),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('development')
    })
  ],

It works good. But when I move it to scripts folder and add ../ before components/index.tpl.html Webpack stops working:

azat@pc:~/git/azat-io$ npm start

> azat-io@ start /home/azat/git/azat-io
> node ./scripts/server

==> 馃寧  Listening on port 8104. Open up http://0.0.0.0:8104/ in your browser.
webpack built 7cb894cd84deca249eae in 7625ms
Version: webpack 1.12.14
Time: 7625ms
                               Asset     Size  Chunks       Chunk Names
7ea725bb351d98c863fb412580e5bf44.png   170 kB               
                             main.js  2.49 MB       0       main

ERROR in   Error: Child compilation failed:
  Entry module not found: Error: Cannot resolve 'file' or 'directory' /home/azat/git/components/index.tpl.html in /home/azat/git/azat-io:
  Error: Cannot resolve 'file' or 'directory' /home/azat/git/components/index.tpl.html in /home/azat/git/azat-io

  - compiler.js:78 
    [azat-io]/[html-webpack-plugin]/lib/compiler.js:78:16

  - Compiler.js:214 Compiler.<anonymous>
    [azat-io]/[webpack]/lib/Compiler.js:214:10

  - Compiler.js:403 
    [azat-io]/[webpack]/lib/Compiler.js:403:12

  - Tapable.js:67 Compiler.next
    [azat-io]/[webpack]/[tapable]/lib/Tapable.js:67:11

  - CachePlugin.js:40 Compiler.<anonymous>
    [azat-io]/[webpack]/lib/CachePlugin.js:40:4

  - Tapable.js:71 Compiler.applyPluginsAsync
    [azat-io]/[webpack]/[tapable]/lib/Tapable.js:71:13

  - Compiler.js:400 Compiler.<anonymous>
    [azat-io]/[webpack]/lib/Compiler.js:400:9

  - Compilation.js:577 Compilation.<anonymous>
    [azat-io]/[webpack]/lib/Compilation.js:577:13

  - Tapable.js:60 Compilation.applyPluginsAsync
    [azat-io]/[webpack]/[tapable]/lib/Tapable.js:60:69

  - Compilation.js:572 Compilation.<anonymous>
    [azat-io]/[webpack]/lib/Compilation.js:572:10

  - Tapable.js:60 Compilation.applyPluginsAsync
    [azat-io]/[webpack]/[tapable]/lib/Tapable.js:60:69

  - Compilation.js:567 Compilation.<anonymous>
    [azat-io]/[webpack]/lib/Compilation.js:567:9

  - Tapable.js:60 Compilation.applyPluginsAsync
    [azat-io]/[webpack]/[tapable]/lib/Tapable.js:60:69

  - Compilation.js:563 Compilation.<anonymous>
    [azat-io]/[webpack]/lib/Compilation.js:563:8

  - Tapable.js:60 Compilation.applyPluginsAsync
    [azat-io]/[webpack]/[tapable]/lib/Tapable.js:60:69

  - Compilation.js:525 Compilation.seal
    [azat-io]/[webpack]/lib/Compilation.js:525:7


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

    ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' /home/azat/git/components/index.tpl.html in /home/azat/git/azat-io
webpack: bundle is now VALID.

What's wrong? Here is a npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart azat-io@
6 info start azat-io@
7 verbose unsafe-perm in lifecycle true
8 info azat-io@ Failed to exec start script
9 verbose stack Error: azat-io@ start: `node ./scripts/server`
9 verbose stack Exit status 1
9 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:214:16)
9 verbose stack     at emitTwo (events.js:87:13)
9 verbose stack     at EventEmitter.emit (events.js:172:7)
9 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
9 verbose stack     at emitTwo (events.js:87:13)
9 verbose stack     at ChildProcess.emit (events.js:172:7)
9 verbose stack     at maybeClose (internal/child_process.js:817:16)
9 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
10 verbose pkgid azat-io@
11 verbose cwd /home/azat/git/azat-io
12 error Linux 3.19.0-30-generic
13 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
14 error node v4.1.1
15 error npm  v2.14.4
16 error code ELIFECYCLE
17 error azat-io@ start: `node ./scripts/server`
17 error Exit status 1
18 error Failed at the azat-io@ start script 'node ./scripts/server'.
18 error This is most likely a problem with the azat-io package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error     node ./scripts/server
18 error You can get their info via:
18 error     npm owner ls azat-io
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]

Most helpful comment

what was the problem?

All 4 comments

Excuse for troubling. I found the error.

what was the problem?

I had this error, and the issue was found by using the --display-error-details flag for webpack.

in my case it uncovered that i needed to add '' to my resolve.extensions array in my webpack config, as it was trying to resolve template.ejs.js, template.ejs.json, etc. rather than template.ejs

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NeverwinterMoon picture NeverwinterMoon  路  3Comments

GerkinDev picture GerkinDev  路  3Comments

maxcnunes picture maxcnunes  路  4Comments

lcxfs1991 picture lcxfs1991  路  4Comments

mmjamal picture mmjamal  路  3Comments