输入npm run webpack 可以执行 不过报以下错误 把注释的loader放出来就执行不了了 而且还报一大堆错误
来源:4-3 plugins-1
慕尼黑0510008
2022-02-17 19:36:12
> webpack@1.0.0 webpack
> webpack --config webpack.config.js
Hash: 5003a6286534ec9b988b
Version: webpack 4.44.1
Time: 196ms
Built at: 2022/02/17 下午7:31:58
Asset Size Chunks Chunk Names
ajax.js 8.41 KiB ajax [emitted] ajax
index.html 2.95 KiB [emitted]
index.js 12.3 KiB index [emitted] index
Entrypoint index = index.js
Entrypoint ajax = ajax.js
[./src/ajax.js] 2.93 KiB {ajax} {index} [built]
[./src/index.js] 1.43 KiB {index} [built]
ERROR in ./src/ajax.js
Module not found: Error: Can't resolve './const.js' in '/Users/chenchenshaobing/Desktop/js/src'
@ ./src/ajax.js 1:0-63 89:29-43 93:29-40 105:34-42 114:63-77 117:63-74
ERROR in ./src/index.js
Module not found: Error: Can't resolve './const.js' in '/Users/chenchenshaobing/Desktop/js/src'
@ ./src/index.js 2:0-102 17:23-32 18:26-39 23:22-27 24:22-31 30:21-26 31:21-30 37:25-32 38:25-36 47:16-25 48:12-17 49:12-17 50:14-21
ERROR in ./src/ajax.js
Module not found: Error: Can't resolve './default.js' in '/Users/chenchenshaobing/Desktop/js/src'
@ ./src/ajax.js 2:0-37 9:38-45
ERROR in ./src/ajax.js
Module not found: Error: Can't resolve './utils.js' in '/Users/chenchenshaobing/Desktop/js/src'
@ ./src/ajax.js 4:0-62 68:8-18 68:28-37 90:15-24 94:23-36
Child HtmlWebpackCompiler:
1 asset
Entrypoint HtmlWebpackPlugin_0 = __child-HtmlWebpackPlugin_0
[./node_modules/html-webpack-plugin/lib/loader.js!./index.html] 3.31 KiB {HtmlWebpackPlugin_0} [built]
weback.js代码
const path=require('path');
const HtmlWebpackPlugin=require('html-webpack-plugin');
module.exports={
mode:'development',
entry:{
index:'./src/index.js',
ajax:'./src/ajax.js'
},
output:{
path:path.resolve(__dirname,'dist'),
filename:'[name].js'
},
module:{
rules:[
{
test:/\.js$/,
exclude:/node_modules/,
//loader:"babel-loader",
}
]
},
plugins:[
new HtmlWebpackPlugin({
template:'./index.html',
})
]
}
1回答
好帮手慕小李
2022-02-18
同学你好,按照同学提供的webpack.config.js代码老师进行了测试,发现报错ajax.js文件没有找到,于是老师在src文件夹下创建了一个ajax.js文件,并打包结果是可行的。如下:

所以这里同学看看src文件夹下是不是有ajax.js。如果有那么看看是否是路径错误。
另如同学搭配babel-loader,解决方案首先排查一下package.json中的配置。

.babelrc文件是否已经有了。

放开注释

使用npm run webpack命令打包,最后生成dist文件夹。

同学按照步骤试试,祝学习愉快!
相似问题