-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix: allow javascript dependencies to import other files without a file extension #31150
base: develop
Are you sure you want to change the base?
fix: allow javascript dependencies to import other files without a file extension #31150
Conversation
|
Is there some way to try this locally, can't find the webpack configs in my node_modules. Maybe a PR version I can try? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Netail
Thank you for the contribution PR! I am not entirely sure this PR is completely passive but I think it should be, but I am also not convinced it fixes the issue. To help verify, are you able to provide a light reproduction of the extension problem you are seeing that I can run on my end? I'm curious to see what the bundle looks like.
On a side note, I think you need to run the linter on these files (should be a comma after the false
).
Right now Cypress does some odd things when trying to run ESM Typescript projects. We are working on replacing the method we use to load and parse cypress typescript configs/projects for Cypress 15 which I would also like to run against your sample project if you are able to upload one.
Hi @AtofStryker Regarding the formatting, I used the online VSCode editor, but will get that sorted too |
Here is a repro: : https://github.com/Netail/repro-cypress-esm, the instructions can be found in the README. |
I was able to pull the repro down and run cypress against your branch. Unfortunately it doesn't fix the issue you are experiencing, but I think that is mostly due to This wouldn't be something we would add since we expect dependencies to be transpiled already and would negatively impact the performance of the preprocessor, but if it is something you need you can download @cypress/webpack-preprocessor and pass in the webpack options you need there. |
But the thing is, the package IS transpiled to Javascript with TSC. It's just that the current webpack configuration does not like ESM imports/exports without a file extension.
I think that would only be the case if it also had to transpile packages from Typescript to Javascript, only disabling fullySpecified won't make that much of a difference (if any at all). -- And as the guys at Typescript mentioned they won't modify import/export URLs. I think from a DX point of view, supporting imports/exports without a file extension (The output by TSC), would be nice :) We could add a seperate entry in the webpack config which disables fullySpecified for all js/mjs files (separate from the one excluding node_modules) And it does seem like other people have ran into the same issue before (in their case Angular dependencies);
Preventing this issue, instead of manually adding a workaround would be great in terms of DX |
3c291bb
to
14feb6b
Compare
Additional details
When a dependency used by cypress specs was compiled to javascript and has type
"type": "module",
in the package.json, it throws the following error:As the default typescript transpiler (tsc) does not add file extensions to the imports & exports I think it's best to allow resolving imports without a file extension by default.
Solution by: webpack/webpack#11467 (comment)
Also setting
"moduleResolution": "Bundler",
in the tsconfig.json does not seem to make a differenceKind of like:
https://stackoverflow.com/questions/62619058/appending-js-extension-on-relative-import-statements-during-typescript-compilat
https://stackoverflow.com/questions/75807785/why-do-i-need-to-include-js-extension-in-typescript-import-for-custom-module
But on webpack level instead of runtime
Steps to test
Have a helper package which QAs can use, transpiled from typescript with tsc and use it in Cypress specs.
How has the user experience changed?
Easier support for external helper packages transpiled by typescript
PR Tasks
cypress-documentation
?type definitions
?