Webpack Error - Cannot Resolve File or Directory

后端 未结 3 1324
抹茶落季
抹茶落季 2021-01-11 09:56

I am getting this error when I npm start my webpack-dev-server:

ERROR in multi main
Module not found: Error: Cannot resolve \'file\' or \'directory\' /var/ww         


        
相关标签:
3条回答
  • 2021-01-11 10:15

    ok if any one face this problem, you can solve it in 2 methods:

    Method 1:

    1- add a file called package.json inside your entry folder (in your case put it inside the folder "{project_dir}/app/package.json")

    2- inside this file write any json object for example:

    {
      "name": "webpack why you do diss :("
    }
    

    Method 2:

    Change your entry files to be at least 2 level away from your project home directory, for example: "{project_dir}/src/app"

    Explanation: for each entry file webpack will try to find a file called package.json to use it for webpack configuration incase this entry file is a module, when you put your entry file only 1 level away from your project home dir webpack will use your project packge.json as configuration file for your entry file and it will fail because of miss configuration.

    0 讨论(0)
  • 2021-01-11 10:33

    You should check the browser console. It provides more detailed informations.

    In my case:

    Uncaught Error: Cannot find module "./src/index"
    at webpackMissingModule (webpack:///multi_main?:4)
    at eval (webpack:///multi_main?:4)
    at Object.<anonymous> (bundle.js:586)
    at __webpack_require__ (bundle.js:556)
    at bundle.js:579
    at bundle.js:582
    

    So here is the error a missing (or misspelled) java script file.

    0 讨论(0)
  • 2021-01-11 10:33

    The same problem I met. I found an answer in github Error : ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory'#981. But sadly, in webpack 1.15.12, the --allow-incompatible-update has been remove. Also, I found when set the entry type is array, such as entry: [entry.js], webpack will run, but throw another error:(

    I wish it can help you, hopefully.

    0 讨论(0)
提交回复
热议问题