npm ERR! Exit status 2

在学习 webpack 的时候出现了一个问题 npm 打包的时候直接报错了。

错误展示
ERROR in ./src/main.js
Module not found: Error: Can't resolve './css/index' in 'D:\webpack_space\learn-webpack\src'
 @ ./src/main.js 3:13-35
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/dist/cjs.js!node_modules/less-loader/dist/cjs.js!src/css/less.less:
    Entrypoint undefined = extract-text-webpack-plugin-output-filename
    [./node_modules/css-loader/dist/cjs.js!./node_modules/less-loader/dist/cjs.js!./src/css/less.less] 217 bytes {0} [built]
        + 1 hidden module
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/dist/cjs.js!node_modules/sass-loader/lib/loader.js!src/css/sass.sass:
    Entrypoint undefined = extract-text-webpack-plugin-output-filename
    [./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/lib/loader.js!./src/css/sass.sass] 184 bytes {0} [built]
        + 1 hidden module
Child html-webpack-plugin for "index.html":
                                          Asset      Size  Chunks             Chunk Names
    images/a4cba8674b30938bf41eacf2d04b3b52.jpg  22.4 KiB          [emitted]
     + 1 hidden asset
    Entrypoint undefined = index.html
    [./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html] 440 bytes {0} [built]
    [./src/images/1.jpg] 89 bytes {0} [built]
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `webpack --config=config/webpack.dev.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\zhoulin\AppData\Roaming\npm-cache\_logs\2019-03-22T10_35_54_503Z-debug.log

其实遇到这种 Exit status 2 的问题,都是因为缺失依赖关系造成的原因较多。例如,需要的文件没有找到,或者是依赖的包有问题。现在就来看看问题,里面有一句话“Module not found: Error: Can't resolve './css/index' in 'D:\webpack_space\learn-webpack\src” @ ./src/main.js 3:13-35 因为有个文件它不知道按照什么类型来处理。来看具体的代码

这就是@ ./src/main.js 3:13-35

因为 index.css 没有添加后缀名,其实解决办法也很方便。我们可以让webpack自己去找例如:

// webpack.config.js 中配置
model.exports = {
  resolve: {
        extensions: [".ts", ".js", ".css"]
    }
}

你可能感兴趣的:(npm ERR! Exit status 2)