Node js Webpack命令不起作用

时间:2018-07-27 13:55:38

标签: webpack

你好,我正在使用webpack,当我运行“ webpack entry bundle.js”时,它会生成此错误消息

Version: webpack 4.16.3
Time: 596ms
Built at: 2018-07-27 06:43:09
 1 asset
Entrypoint main = main.js
[0] multi ./script1.js ./bundle.js 40 bytes {0} [built]
[1] ./script1.js 192 bytes {0} [built] [failed] [1 error]

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/

ERROR in multi ./script1.js ./bundle.js
Module not found: Error: Can't resolve './bundle.js' in 'C:\Users\...\webpack_'
 @ multi ./script1.js ./bundle.js main[1]

ERROR in ./script1.js 1:34
Module parse failed: Unexpected token (1:34)
You may need an appropriate loader to handle this file type.
> var message = require('./script2'):
|
| alert(message);
 @ multi ./script1.js ./bundle.js main[0]

我已将所有文件放在同一文件夹中。

script1.js文件

var message = require('./script2'):
alert(message);

script2.js文件

module.exports  = "hello";

谢谢

1 个答案:

答案 0 :(得分:1)

现在我明白了。 将入口点放在./src文件夹中,并将下面的代码添加到package.json文件中

"scripts": {
  "dev": "webpack --mode development ./src/index.js --output ./bundle.js",
  "build": "webpack --mode production ./src/index.js --output ./bundle.js"
  }

然后在终端上运行此npm run dev命令。它有效! 如需更多帮助,请访问https://www.valentinog.com/blog/webpack-tutorial