[Bug] Typescript Declaration file error
See original GitHub issuePlease convert dayjs/esm/index.d.ts to export default dayjs

Declaration file is using export = which is same to exports in cjs, while the actural code is export default which is exports.default in cjs.
This makes error when the env not allow users to open allowSyntheticDefaultImports and esModuleInterop
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Could not find a declaration file for module 'module-name ...
Here are two other solutions. When a module is not yours - try to install types from @types : npm install -D @types/module-name....
Read more >Fixing the TS7016 Error | Atomist Blog
Could not find declaration file -- How do you get past the TS7016? This article highlights the eight best and worst fixes.
Read more >TypeScript errors and how to fix them
Common Errors. Below you find a list of common TypeScript errors along with the buggy code and its fixed version. If you're interested...
Read more >Troubleshooting | ts-node - TypeStrong · GitHub
Any error that is not a TSError is from node.js (e.g. SyntaxError ), and cannot be fixed by TypeScript or ts-node. These are...
Read more >TSConfig Reference - Docs on every TSConfig option
An error occurs if any of the files can't be found. ... exactOptionalPropertyTypes makes TypeScript truly enforce the definition provided as an optional ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Just to understand the problem I created demo projects for all cases:
const dayjs = require('dayjs')and with just a plainpackage.json=> everything runs as expectedimport dayjs from 'dayjs'and with"type": "module"in thepackage.json=> everything runs as expectedimport dayjs from 'dayjs'and with just a plainpackage.jsonand with"compilerOptions": {"allowSyntheticDefaultImports": true, "esModuleInterop": true}in thetsconfig.json=> everything runs as expected, as in my understanding this boils down to using the library as umd-/commonjs packagesNow IMHO @iamkun made the clever decision to integrate dayjs as esm package in the generated package in form of a subfolder called
dayjs/esm.So in my program (that is using the dayjs package) if and only if I want to use
dayjsas an esm module, I would usedayjs/esminstead ofdayjswithout changing any other code.If I do this with
dayjs/esmjust out of the box, I get the effect that node complains about a missing"type": "module"(as the nextpackage.jsonup the line does not contain such an entry - and should not, as this would kill the usage ofimport from 'dayjs').package.jsonwith"type": "module"into the folderdayjs/esmand without"compilerOptions": {"allowSyntheticDefaultImports": true, "esModuleInterop": true}in thetsconfig.json(ok and I fixed the type definition files to match theexport defaultof the*.jsfiles and have named exports too) and now this runs like a charm.This way we could have both worlds without using 2 packages (
dayjsand e.g.dayjs-esm) and without the problems described in issue #1281 (because like you all confirmed, there is no simple way to configurepackage.jsonof a library so that it is possible to use this library as umd/commonjs and esm - at least not in an node environment).Using 2 different packages is something we should avoid, as this makes development of this great package not really easier - I suppose.
And to the question of semantic versioning: is this really a major (i.e. breaking) change? We only change the type definitions and at least I could not get the current type definitions into compiling without error - so does anyone else?
Or does my “great” solution (just joking 😃 miss some side effects that would kill any existing application using dayjs? At the moment all existing solutions should be using the path
dayjs, shouldn’t they)?this will introduce a new problem, please refer to #1281