Closed ArthurGoupil closed 2 days ago
Thanks! Now is docusaurus (so, webpack) to fail with:
Module not found: Error: Can't resolve './' in '/home/runner/work/react-day-picker/react-day-picker/dist/esm'
Did you mean 'index.js'?
BREAKING CHANGE: The request './' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
My understanding is that we need to update also the import statements to use index.js
and the file extensions. How do we do this with the TypeScript compiler?
Hello there! Jumping on this to help unlock this esm/cmjs issue.
tsc
(tsc --project tsconfig-esm.json
)my/path/index.js
instead of my/path
).tsc
as no ability to transform the path in to fully specified version at build time (see for example this issue)dist/esm
output dir don't have fully specified import/export paths, and this is an issue for tools that want to leverage strict ESM imports (here: docusaurus)"type": "module"
, tools that can leverage ESM are more likely to do so. For example docusaurus is now trying to import the ESM files.See also https://dev.to/ayc0/typescript-50-new-mode-bundler-esm-1jic
In the ECMAScript spec, they mention that imports need to have a file extension, so import { foo } from './foo'; is not valid (see in Node.js’s doc).
We need to output esm files that have fully specified imports. I think we have two options:
make all paths fully specified
Here we need to transform lines like import "./my/path/"
into import "./my/path/index.js" in all source files (note the
.jseven in
.ts` source files.
add a bundler to do this fully specified transformation for us, for example rollup
No change to do on the source files. We will let the bundler do this for us.
Are you opened in adding a bundler like rollup to output common js and esm files @gpbl? We can propose a PR for that with @ArthurGoupil
Hi @guillaumewuip, thanks for the suggestions!
I really prefer adding the extension to the import
rather than introducing rollup.js again. There should be an extension for eslint as well.
Ok, so the next steps is to update this PR by updating each import lines, right?
Basically @ArthurGoupil :
-import {} from './toto'
+import {} from './toto.js'
-import {} from './tata'
+import {} from './tata/index.js'
Ok, so the next steps is to update this PR by updating each import lines, right?
Yes - that should work for everyone.
@gpbl I think there is a blocker here, looks like your testing environment doesn't accept the explicit .js
imports
@ArthurGoupil thanks for looking at it , and sorry for the hassle. Will check it out asap.
@ArthurGoupil it looks like now it pass 🎉
How to add a test to the build pipeline to avoid issues like these? 🤔
Could you maybe try to install main branch
npm install git+https://github.com/gpbl/react-day-picker.git
and confirm it works now for you? Thanks.
Thanks for the updates @gpbl ! I'll test shortly and tell you if I still have issues. But it should be alright now.
Description
There is a missing
type: module
inpackage.json
making jest be lost when trying to use esm/cjs.Type of Change
Checklist
Before submitting your pull request, please make sure the following is done:
Linked Issues
No posted issue
Test Plan
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
Screenshots (if appropriate)
Include screenshots or GIFs if relevant. This is especially important for UI-related changes.
Further Comments
If you have any additional comments or questions, please add them here.