Skip to content

export declared with export = DeviceDetector; forces me to use 'allowSyntheticDefaultImports' #148

Description

@IARI

DeviceDetector is declared with export = DeviceDetector; and no default export is specified.

Our project was configured without 'allowSyntheticDefaultImports'.
With this configuration:

  1. 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 {
// ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions