Module not found: Error: Cannot resolve 'file' or 'directory' ./cats.js in E:\Git\mmall_fe\src\page\

ERROR in multi index
Module not found: Error: Cannot resolve 'file' or 'directory' ./src/page/index/index.js in E:\Git\mm
all_fe
@ multi index

ERROR in multi login
Module not found: Error: Cannot resolve 'file' or 'directory' ./src/page/login/index.js in E:\Git\mm
all_fe
@ multi login

我通过查看设定的输出目录下的app.js的最后一段代码:
function webpackMissingModule() { throw new Error("Cannot find module
最下面一个回答建议:
rm -rf node_modules
rm -rf ~/.npm
npm install -g npm
npm install
这时提示
E:\Git\mmall_fe>npm install
ERROR: npm is known not to run on Node.js v4.4.7
Node.js 4 is supported but the specific version you're running has
a bug known to break npm. Please update to at least 4.7.0 to use this
version of npm. You can find the latest release of Node.js at https://nodejs.org/

于是,我便在官网下载4.7版本安装
安装好,继续执行 npm install命令,然后执行打包webpack终于成功了。



关于安装CommonsChunkPlugin插件
本来配置webpack.config.js是这样配置的,然而打包时死活报错........无奈弄了一个多小时,遂上网找了另外一种写法:

var CommonsChunkPlugin = require ( "webpack/lib/optimize/CommonsChunkPlugin" );
plugins : [
   new CommonsChunkPlugin ({
       name:"commons",
       filename : "js/base.js"
   })
  ]

终于可以了!!!



报错:You may need an appropriate loader to handle this file type.

我准备使用webpack加载css文件并安装插件,
在安装 css-loader和 style-loader插件然后import css文件:
var footerCss =require("../../css/footer.css");
运行后在cmd中会报错:
ERROR in ./css/footer.css
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| .minFooter{
|   background-color: #333333;
|   color:#ffffff;
 @ ./js/compoents/footer.js 21:16-47
 @ ./js/index.js
是因为版本问题,只需把引入的css文件方式改成 var footerCss =require("style-loader!css-loader!../../css/footer.css");

后来...我还在https://www.webpackjs.com/guides/asset-management/#加载-css 找到了最新版本webpack的写法,怪就怪自己升级了webpack最新版.

关于 每次装插件都莫名其妙的很多问题,我最终都通过安装与项目一样的插件版本解决!

猜你喜欢

转载自blog.csdn.net/a600849155/article/details/79770094