简体   繁体   中英

ERROR in multi ./main.js . Module not found: Error: Can't resolve '/home/user/workspace/webpack'

I am facing issues while bundling 2 independent javascript files.

index.html

<html>
<head>
<title>experiment</title>
<script src="main.js"></script>
<script src="new.js"></script>
</head>
<body>
<form>
<button onclick="firstButton();">firstButton</button>
<button onclick="secondButton();">secondtButton</button>
</form>
</body>
</html>

main.js

function firstButton() {

console.log("First Button");    
}

new.js

function secondButton(){
    alert("Second Button");
}

webpack.config.js

module.exports = {
  entry: './main.js',
  output: {
    filename: './bundle.js'
  }
};

when running webpack . command then getting this error on terminal

Hash: 8a3cc31d526703c3b9fa
Version: webpack 2.5.1
Time: 88ms
      Asset     Size  Chunks             Chunk Names
./bundle.js  2.91 kB       0  [emitted]  main
   [0] ./main.js 57 bytes {0} [built]
   [1] multi ./main.js . 40 bytes {0} [built]

ERROR in multi ./main.js .
Module not found: Error: Can't resolve '/home/user/workspace/webpack' in '/home/user/workspace/webpack'
 @ multi ./main.js .

also i tried this webpack.config.js

const config = {
  entry: {
    a : './main.js' ,
    b : './new.js'
  } ,
   output: {
    filename: 'bundle.js',
    path: '/home/user/workspace/webpack'
  }
};

module.exports = config;

this is the error i am getting ..

user@user-ThinkPad-T420s:~/workspace/webpack$ webpack .
Hash: 44a14163f4c0c760c3ad
Version: webpack 2.5.1
Time: 89ms
    Asset     Size  Chunks             Chunk Names
bundle.js  2.69 kB       0  [emitted]  b
   [0] ./main.js 57 bytes {1} [built]
   [1] ./new.js 51 bytes {0} [built]

ERROR in Entry module not found: Error: Can't resolve '/home/user/workspace/webpack' in '/home/user/workspace/webpack'

ERROR in chunk a [entry]
bundle.js
Conflict: Multiple assets emit to the same filename bundle.js

Any argument to the webpack CLI is interpreted as an entry point (see Command Line Interface (CLI) ). When you run:

webpack .

the . corresponds to the current directory and webpack tries to resolve a module from it, which should be used as an entry point.

You're already configuring the entry points in your webpack config, therefore you should run webpack without any arguments:

webpack

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM