-
-
Notifications
You must be signed in to change notification settings - Fork 207
Description
Using the latest v5.2.0 package (containing JS and TypeScript index.d.ts), I've tried the following:
Importing with ESM default:
import Long from "long";
import Long from "long/umd";
// these statements give the following error:
TS1259: Module '"node_modules\\long\\index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
Importing everything with import *, I use this syntax to import CommonJs modules that export a single object (without default) e.g. import * as jquery from 'jquery':
import * as Long from "long";
import * as Long from "long/umd";
TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
When I change my TypeScript module output from ESM to AMD (AMD output permits the require syntax), it will compile:
import Long = require("long");
import Long = require("long/umd");
// unfortunately I'm unable to use this syntax with ESM output, which is a blocker for us:
TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
It's also possible to get this working with v4.0.0 with @types/long v4.0.1 (separate package before types were bundled in v5+) when using the import * as Long from "long" syntax when module output is ESM.
It seems strange to me that the TypeScript declaration exports with = but the JavaScript exports with an ESM default. I suspect the mix/matching of these styles causes the error. The ESM JS/TS should stick to ESM imports/exports and the UMD JS/TS should stick to UMD exports.