DeviceDetector is declared with export = DeviceDetector; and no default export is specified.
Our project was configured without 'allowSyntheticDefaultImports'.
With this configuration:
- an IDE like webstorm will automatically import
DeviceDetector with the line
import * as React from "react";
which will work fine in development, but when the project is built, there will be exceptions, the DeviceDetector constructor will not be found.
Trying to import DeviceDetector with this configuration like this
import DeviceDetector from "device-detector-js";
leads to the following typescript error:
⚠️ Missing/incorrect detections should be reported at https://github.com/matomo-org/device-detector/issues instead of this repo.
TS1259: Module '"C:/dev/viuport/client/node_modules/device-detector-js/dist/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag index.d.ts(34, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
see also https://www.typescriptlang.org/tsconfig#allowSyntheticDefaultImports
I would instead endorse exporting DeviceDetector as default, for example like this
export default class DeviceDetector {
// ...
DeviceDetector is declared with
export = DeviceDetector;and no default export is specified.Our project was configured without 'allowSyntheticDefaultImports'.
With this configuration:
DeviceDetectorwith the linewhich will work fine in development, but when the project is built, there will be exceptions, the
DeviceDetectorconstructor will not be found.Trying to import
DeviceDetectorwith this configuration like thisleads to the following typescript error:
TS1259: Module '"C:/dev/viuport/client/node_modules/device-detector-js/dist/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag index.d.ts(34, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
see also https://www.typescriptlang.org/tsconfig#allowSyntheticDefaultImports
I would instead endorse exporting
DeviceDetectoras default, for example like this