-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable import in TypeScript since v5+ #109
Comments
I was able to import from version 5.0.1 which had |
This makes the TS compatibility checks a bit more robust by fixing a few issues in the codebase as well as changing our TypeScript test configs to include all files rather than just the test files. Note that the `long` package needed downgraded to `5.0.1` (and pinned to patches only) because of an issue in that library with 5.2 and above. See this issue: dcodeIO/long.js#109
Is there any fix coming in for this? Looks like google packages like
I continue to get the error:
|
The source of this error is: Line 446 in 3cea40d
This is only compatible with synthetic ES modules being exported as CommonJS. For true ES modules this should be: export default Long; See the TypeScript documentation which states that separate type definitions can be specified (scroll to the code bubble right after the "The new support works similarly with import conditions." paragraph). |
Thanks @russellsteadman for the PR! There should be a new release at 0 UTC. Lmk if there are remaining issues with the fix in place. |
v5.2.2 shows I'm using ESM + Webpack + TS. |
Reordered in v5.2.3, lmk! |
Any news on this? |
No updates on this for 3 months? |
If it helps anyone, I was able to get around this issue by using The file
|
My recipe for diff --git a/node_modules/long/umd/index.d.ts b/node_modules/long/umd/index.d.ts
index c623535..59c28bb 100644
--- a/node_modules/long/umd/index.d.ts
+++ b/node_modules/long/umd/index.d.ts
@@ -1,2 +1,3 @@
+// @ts-expect-error this fixes the tsc compilation issue and allows us to remove `skipLibCheck` from tsconfig
import Long from "../index.js";
export = Long; |
Using the latest v5.2.0 package (containing JS and TypeScript index.d.ts), I've tried the following:
Importing with ESM default:
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'
:When I change my TypeScript module output from ESM to AMD (AMD output permits the require syntax), it will compile:
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.
The text was updated successfully, but these errors were encountered: