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.
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.
This was a simple error. It occurred due to the missing {}
around the module name in the import statement itself.
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
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
Use:
import { Module } from 'module';
You need to insert the module name between {...}
I fixed it by adding this to tsconfig.json
in my angular project.
{
...
"compilerOptions": {
...
"allowSyntheticDefaultImports": true,
I fixed above issue by putting the following inside the tsconfig.json
file:
{
"compilerOptions": {
...
"esModuleInterop": true
...
}
}
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
}
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!
To solve this problem, instead of exporting the module as named export, we need to make it a default exported module as below
export default class Module {
... your module code
}