webpack: Uncaught Error: Cannot find module "."

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

What is the current behavior? Below exception:

polyfills.js:1 Error: Cannot find module "."
    at webpackMissingModule (eval at 148 (http://localhost:9000/assets/app.js:1:576363), <anonymous>:8:65) [angular]
    at eval (eval at 148 (http://localhost:9000/assets/app.js:1:576363), <anonymous>:8:144) [angular]
    at Object.onInvoke (eval at <anonymous> (http://localhost:9000/assets/vendor.js:1:92060), <anonymous>:4334:37) [angular]
    at eval (eval at 142 (http://localhost:9000/assets/polyfills.js:1:6901), <anonymous>:758:57) [angular]
    at Object.onInvokeTask (eval at <anonymous> (http://localhost:9000/assets/vendor.js:1:92060), <anonymous>:4325:37) [angular]
    at drainMicroTaskQueue (eval at 142 (http://localhost:9000/assets/polyfills.js:1:6901), <anonymous>:591:35) [<root>]
    at <anonymous> [<root>]

If the current behavior is a bug, please provide the steps to reproduce. Configuration files are uploaded on Github gist https://gist.github.com/shafaqkazmi/abbf5b07a70e6d23463d2de7d42f2a53

What is the expected behavior? Application should load all desired modules

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

Version details:

@angular/cli: 1.0.3
node: 7.0.0
os: win32 x64
@angular/common: 4.1.2
@angular/compiler: 4.1.2
@angular/core: 4.1.2
@angular/forms: 4.1.2
@angular/http: 4.1.2
@angular/platform-browser: 4.1.2
@angular/platform-browser-dynamic: 4.1.2
@angular/router: 4.1.2
@angular/cli: 1.0.3
@angular/compiler-cli: 4.1.2

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 11
  • Comments: 57 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I think i found a solution, at least for Ionic. I have no idea what’s causing this, but it appears that i get the error when some imports add “/umd” at the end. For instance: import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular/umd'; i made a search in the whole project looking for “/umd” and deleted them: import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular'; , and it worked!

I had two projects with the same problem, and i fixed both by doing this… Again, i don’t know if it’s VS Code Insiders that’s automaticly adding this or a plugin i have installed or something…

Are you all using VS Code?

Happened to me as well, turns out it was because i was using require with an expression instead of a value:

var path = 'path/to/file.js' 
require(path) // Error: Cannot find module "."
require('path/to/file.js' ) // All good

Since module resolution is static - variables are not allowed, so you could just go with

require(`${path}`)

it helped me:

require(`${path_to_file}`);

and if you need more variable in your dynamic path try split require:

function getIcon(name) {
  const [category, filename] = name.split(":");

  if (filename) {
    return require(`one_directory/icons/${category}/${filename}.svg`);
  } else {
    return require(`two_directory/icons/${name}.svg`);
  }
}

npm i -D typescript@2.8.3 fixed it for me.

@danielzlotnik +1 Is there a solution?

Ran into the same issue (not using Ionic), unable to use template literals within the require after upgrading to Babel 7. We are currently using webpack 2.x and will be upgrading to 4 soon - I believe this has to do with new babel + older webpack not being friendly in my scenario.

Not Working

config = require(`../inc/${process.env.targetNetwork}.config.json`);

Working

config = require('../inc/' + process.env.targetNetwork + '.config.json');

This is the temporary fix I’ve applied that works for me. Hope this helps someone in the future 👍

I’m having this issue, but with import() 😦

Yep, Vs Code added /umd to import statement. It could be the auto import plugin. (I am using Vs Code and Ionic)

I use the solution proposed by @killian2301. In my case when I did a find/replace in vscode, the postfix /umd was automatically added to the import of the Ionic libraries:

import {Events, Nav, Platform, Config } from 'ionic-angular/umd';

I removed the / umd and with that the error was fixed:

import { Events, Nav, Platform, Config } from 'ionic-angular';

I have the same issue using import in ionic. Any suggestions?

This Solution by @padurets actually solved the issue for me (I’m working on a Vue-Cli 3 project), and I’m getting the path from the Store (Vuex) within a Computed function in my component.

require(`${path_to_file}`);

Thanks a lot @padurets !

Decreasing the version to ~2.6.2 fixed it.

In my case it solved the problem by removing /umd from import pathes.

Search and replace all occurrences of ionic-angular/umd with ionic-angular.

I don’t know why is /umd set on the pathes. And I’m sure it also working with /umd. The problem comes suddenly. In my case I renamed a few files in my sources. But rebuilt incl. clean. Usually it works. This error (cannot find module “.”) is rare but persistent.

@Kaidanov that worked for me too last time…only this time the problem didn’t appear after generating a page, but renaming it…

npm i -D typescript@2.8.3 fixed it for me.

Me to !! Thank’s really 😂

@killian2301 it works for me. After hours looking for the problem, I solved it remoming all “/umd” statements from all imports that was added when I created a new Page.

@rihlsul Just recompile / restart the app and the styles comes back. I had the same problem. After removing all umd from imports, the html of my app (ionic) was naked. But a rebuild fixed this issue.

Sounds like it’s coming from this: https://github.com/Microsoft/TypeScript/issues/25204

However, when I did replace all on my project to remove all /umd instances, my UI is now borked. Completely unstyled. Will report back if I can figure out what the heck I did.

save my day @killian2301 thought it was just my code structure that causes the fucking error haha 😃
cheers!!!

thanks @killian2301 that’s the perfect solution, in my case the umd comes when use isUndefined function. ;o)

I’m getting the same error with Ionic 3 also… @jayzyaj did you get to solve it? Last time i had to start a new project again…

Can you provide a minimal sample repo that shows that issue?