fix type in umd module export
import Long from "../index.js";
export = Long;
previous code generates errors complaining about cannot import from ESmodule to commonJS. a workaround is to duplicate the content of index.d.ts
node_modules/long/umd/index.d.ts:1:18 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("../index.js")' call instead.
1 import Long from "../index.js"; ~~~~~~~~~~~~~
Found 1 error in node_modules/long/umd/index.d.ts:1
this may not be the best solution because it duplicates the index.d.ts. However I tried a few ways and this is the only one that works to me.
This fixed the problem for me.
This fixes my build too. What I am struggling to understand is why this is posing a problem only now, i've been running this code fine the past months
any news about it? it should be merged and populated to npm
It has been about 4 months since this PR is out and as you can see we really need this change to be merged and publish to NPM so that a lot of users (#124, #125) will be happy.
I understand that as the code owner you may have some concerns about this PR (eg. duplicated source file for the .d.ts). How about we apply this fix first and then try to improve it later? A not-so-good solution is better than none.
@fs-eire @henriquecarv I think if you invert the import dependencies this should work without duplication:
// umd/index.d.ts
declare class Long {
// ...
}
export = Long;
// index.d.ts
import Long from './umd/index.js';
export default Long;
Oh never mind I see that's what they've proposed in https://github.com/dcodeIO/long.js/pull/130
Would recommend closing this PR in favour of that one.
@fs-eire this is not work for me when I use protobuf.
case 4:
if (tag !== 32) {
break;
}
message.int64Field = longToNumber(reader.int64() as Long);
continue;
src/tdo/type_test.ts:228:63 - error TS2709: Cannot use namespace 'Long' as a type.
228 message.int64Field = longToNumber(reader.int64() as Long);