error TS1192: Module '" A.module"' has no default export
AngularTypescriptAngular2 ModulesAngular 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:
- Open SVGR
- Copy your .svg file source code and paste it in SVG Input
- Create a file with name: SvgComponent.jsx in your project directory
- 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';