webpack Uncaught Error: Cannot find module “.”

Do you want to request a feature or report a bug?

What is the current behavior?

Uncaught Error: Cannot find module "."
    at webpackMissingModule (index.js?3672:20)
    at _import (index.js?3672:20)
    at eval (index.js?3672:27)
    at Object../src/router/index.js (app.js:1038)
    at __webpack_require__ (app.js:679)
    at fn (app.js:89)
    at eval (main.js?1c90:1)
    at Object../src/main.js (app.js:1023)
    at __webpack_require__ (app.js:679)
    at fn (app.js:89)


If the current behavior is a bug, please provide the steps to reproduce.
1、clone https://github.com/rawbin-/vue-webpack-test
2、npm install && npm run dev
3、see the browser console


What is the expected behavior?

the following code both run as expected

// router/index.js
import Vue from 'vue'
import Router from 'vue-router'


// this piece of code works
// const _import = (relativePath) => {
//   if (process.env.NODE_ENV === 'development') {
//     return require('@/components/' + relativePath).default
//   } else {
//     return import('@/components/' + relativePath)
//   }
// };

// the following code does not work
// Uncaught Error: Cannot find module "."
const _import = (relativePath) => {
  const fullRelativePath = '@/components/' + relativePath;
  if (process.env.NODE_ENV === 'development') {
    return require(fullRelativePath).default
  } else {
    return import(fullRelativePath)

const HelloWorld = _import('HelloWorld');

export default new Router({
  routes: [
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld

If this is a feature request, what is motivation or use case for changing the behavior?

changing the fullRelativePath for other reason

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

Node 8.11.1 MacOS High Sierra 10.13.4 tested on webpack 3.6.0 2.6.1,and both fails

related to this #4921

Author: Fantashit

1 thought on “webpack Uncaught Error: Cannot find module “.”

  1. full dynamic impports/requires are not supported. Also check the warnings/errors you get while compiling.

Comments are closed.