webpack: Module not found: Error: Can't resolve (with relative path)

前端 未结 10 1970
长情又很酷
长情又很酷 2021-02-05 06:34

I have this structure of an app (node_modules dir excluded from this list):

├── actions.js
├── bundle.js
├── components
│   ├── App.js
│   ├── Foote         


        
相关标签:
10条回答
  • 2021-02-05 07:16

    If you use multiple node_modules (yarn workspace etc), tell webpack where they are:

      externals: [nodeExternals({
        modulesDir: path.resolve(__dirname, '../node_modules'),
      }),  nodeExternals()],
    
    0 讨论(0)
  • 2021-02-05 07:18

    Just ran into this... I have a common library shared among multiple transpiled products. I was using symlinks with brunch to handle sharing things between the projects. When moving to webpack, this stopped working.

    What did get things working was using webpack configuration to turn off symlink resolving.

    i.e. adding this in webpack.config.js:

    module.exports = {
      //...
      resolve: {
        symlinks: false
      }
    };
    

    as documented here:

    https://webpack.js.org/configuration/resolve/#resolvesymlinks

    0 讨论(0)
  • 2021-02-05 07:19

    Look the path for example this import is not correct import Navbar from '@/components/Navbar.vue' should look like this ** import Navbar from './components/Navbar.vue'**

    0 讨论(0)
  • 2021-02-05 07:25

    while importing libraries use the exact path to a file, including the directory relative to the current file, for example:

    import Footer from './Footer/index.jsx'
    import AddTodo from '../containers/AddTodo/index.jsx'
    import VisibleTodoList from '../containers/VisibleTodoList/index.jsx'
    

    Hope this may help

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