I am running into an issue with importing classes from different files in my Typescript node project. The classes being imported to certain files appear to be undefined. Here is my setup simplified:
I have 3 files in the same folder:
product.ts
import CommonController from './common';
export default class ProductController extends CommonController {}
product-price.ts
import ProductController from './product';
export const defaultCustomProductPriceController =
new CustomProductPriceController({
nestedQueries: [
{
nestedPropertyName: 'promotions',
nestedPropertyClass: new PromotionController({
nestedQueries: [
{
nestedPropertyName: 'freeProduct',
nestedPropertyClass: new ProductController({})
}
]
})
}
]
});
custom-product-price.ts
import ProductController from './product';
export const defaultCustomProductPriceController =
new CustomProductPriceController({
nestedQueries: [
{
nestedPropertyName: 'promotions',
nestedPropertyClass: new PromotionController({
nestedQueries: [
{
nestedPropertyName: 'freeProduct',
nestedPropertyClass: new ProductController({})
}
]
})
}
]
});
The error I am getting is in my product-price.ts file. When I try and run the code I just get the error:
i.default is not a constructor
If I change the code in product-price.ts to not import the ProductController and instead just declare it inline in the file like so it does not throw any errors:
product-price.ts
import CommonController from './common';
class ProductController extends CommonController {}
export const defaultCustomProductPriceController =
new CustomProductPriceController({
nestedQueries: [
{
nestedPropertyName: 'promotions',
nestedPropertyClass: new PromotionController({
nestedQueries: [
{
nestedPropertyName: 'freeProduct',
nestedPropertyClass: new ProductController({})
}
]
})
}
]
});
I am baffled as to what is going on as I have used this pattern a lot in my app and had no issues with it.
Why would ProductController be importing as undefined in one file and perfectly fine in the next?
from i.default is not a constructor - why is my import undefined in one file and valid in the next?
No comments:
Post a Comment