error TS1192: Module '" A.module"' has no default export

AngularTypescriptAngular2 Modules

Angular Problem Overview


I have created a new module 'A' and trying to import it in another module called 'B'. I am getting this error on compiling that says

> error TS1192: Module '" A.module"' has no default export

Can anyone please help on how to solve this error.

Angular Solutions


Solution 1 - Angular

This was a simple error. It occurred due to the missing {} around the module name in the import statement itself. Since this killed 2-3 hours of my time, sharing with you all so you won't waste yours. Hope this can help someone. Cheers, Abhi.

Solution 2 - Angular

Accepted answer didn't work for me, so I am posting more info.

I had:

import Module from 'module';

and this worked for me:

import * as Module from 'module';

src: https://github.com/Microsoft/TypeScript/issues/3337#issuecomment-107971371

Solution 3 - Angular

Use:

import { Module } from 'module';

You need to insert the module name between {...}

Solution 4 - Angular

For me this issue was addressed using "allowSyntheticDefaultImports": true within compilerOptions in the project's tsconfig.json.

Our specific error related to a moment js import.

More about this option can be found here

Solution 5 - Angular

I fixed it by adding this to tsconfig.json in my angular project.

{
  ...
  "compilerOptions": {
    ...
    "allowSyntheticDefaultImports": true,

Solution 6 - Angular

Instead of importing it as module, you can also require it like so:

const Module = require('./some_folder/module');

module.ts would then have:

module.exports = class Module {
    ... your module code
}

Solution 7 - Angular

I fixed above issue by putting the following inside the tsconfig.json file:

{
  "compilerOptions": {
    ...
    "esModuleInterop": true
    ...
  }
}

Solution 8 - Angular

All above answers didn't solve my error. Below solution worked for me. Before this, I have run below command

npm i @types/moment-timezone --save-dev

And then I imported moment like below in .ts file.

import * as moment from "moment-timezone";

I hope, it will help someone. Thanks!

Solution 9 - Angular

You can convert your .svg to a SVG React component by using SVGR Tool

Instructions:

  1. Open SVGR
  2. Copy your .svg file source code and paste it in SVG Input
  3. Create a file with name: SvgComponent.jsx in your project directory
  4. Paste the jsx code from the JSX Output in this new .jsx file

To use your SVG React Component do:

import SvgComponent from '../assets/SvgComponent';

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbhiView Question on Stackoverflow
Solution 1 - AngularAbhiView Answer on Stackoverflow
Solution 2 - Angularnothing-special-hereView Answer on Stackoverflow
Solution 3 - AngularRafael TovarView Answer on Stackoverflow
Solution 4 - AngularMichael HancockView Answer on Stackoverflow
Solution 5 - Angulartbo47View Answer on Stackoverflow
Solution 6 - AngularJosé VeríssimoView Answer on Stackoverflow
Solution 7 - AngularziishanedView Answer on Stackoverflow
Solution 8 - AngularRajeev KumarView Answer on Stackoverflow
Solution 9 - Angularraghav-wdView Answer on Stackoverflow