-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
CJS plugins file (and ideally also allowing an ESM one) #16467
Comments
my workaround was switching |
Yeah, thanks. In my case, however, I'm not using TS and not inclined to do so. |
Could I ask where this might fit on your overall priorities? I don't see anything at https://docs.cypress.io/guides/references/roadmap but this is kind of a blocker for many projects wishing to convert to native ESM. Thanks! |
Brett, can you provide an example of what you are trying to do? Like specific code a d 3rd party modules that are not supporting the node require in the plug-in file ?
…Sent from my iPhone
On Jul 9, 2021, at 21:28, Brett Zamir ***@***.***> wrote:
Could I ask where this might fit on your overall priorities? I don't see anything at https://docs.cypress.io/guides/references/roadmap but this is kind of a blocker for many projects wishing to convert to native ESM. Thanks!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
As per the blog post referenced in the OP, the prolific npm publisher, sindresorhus (over 1100 projects, many of which are well-used) has begun migrating projects to be ESM only. (One popular one, I would very much prefer to migrate to ESM (as I have already begun to do on my non-UI projects) for various reasons:
ESM appears to be a popular development (e.g., some feature requests related to ESM indicate "strongly positive" feedback from web developers on the likes of import maps), and I think developers are just eager to finally make the transition, particularly I would imagine, those developers who are concerned enough about the quality and up-to-date maintenance of their code, such as Cypress users I would imagine would tend to be. I expect at least sindresorhus' projects are likely to nudge some to make the transition in the present or nearer future (not to mention I now can't use my own ESM-only projects I already have created, either! :-) ), but as mentioned, my main concern at this point is not so much that I have to change now, so much as that I can't set my projects up as I'd like or need to do my own extra build steps for others' (or my own) code. So this might not be a huge blocker yet, but with Node 10 end-of-lifed, native ESM is now available, and people such as myself do want to start using it (and not being forced to use ".mjs" everywhere), as well as follow a best practice that many projects have been following well before native ESM was available, not to mention get access to the smaller number of ESM-only packages that are being created. Thanks! |
Can you set up a tiny example repo that fails to run because of esm module use? So what we discuss is concrete rather than abstract? |
Sure. See https://github.com/brettz9/cypress-esm . It is a very minimalist repo, as it is easy to reproduce. See the README for how the options to try to fix it (without getting rid of |
I wanted to chime in to say that I just installed cypress and ran Edit: nevermind, changing the name to |
@IanVS did you get Cypress working with type:'module' ? |
Yes, I changed my files to typescript which works fine. My point was to mention that the experience is somewhat broken for new users. |
one more here for cjs please |
+1 for ESM support, this is the only tool I use that doesn't support it, I have to manually remove the I would suggest doing something similar to Jest, it catches the ESM error after require and does a dynamic import, https://github.com/facebook/jest/blob/09278348b355c0450ddd6d40d074e69e4add688e/packages/jest-util/src/requireOrImportModule.ts#L34 I wrote an article about migrating a server and it's tools to ESM here that might be useful for reference https://medium.com/@albertstill/is-node-ready-for-native-ecmascript-modules-b8c6d5463d67 |
A simple workaround, till Cypress enables {"type": "commonjs"} This tells Node.js that all "js" files in this folder are CJS, and Cypress will load them without any problem. |
Lack of ESM support in Cypress is indeed a bit of a buzkill. We're trying to incrementally migrate our project to ESM. We started with Webpack configs and had to revert because of Cypress - we reuse our webpack configs in Cypress setup and aren't able to import |
The trick mentioned by @giltayar works for me, too. I don't need one for the support folder, since that seems to just work fine when webpack'ed. I am using |
One important detail though is that since the plugins file is commonJS, the only way to use your esm modules is via dynamic import, e.g. const webpackPreprocessor = require("@cypress/webpack-preprocessor");
module.exports = async (on, config) => {
const {default: webpackOptions} = await import("../../webpack.config.mjs");
on("file:preprocessor", webpackPreprocessor({
webpackOptions,
}));
... |
Works for me @dbo, thank you!! |
New user of Cypress here and this really caused me a lot of headaches. |
this also has stopped working for me after some version upgrades :/ |
I think we are now working with type: module. Is this still an issue? |
Yes, seems to be working now, thanks, so closing. |
Especially with Node 10 reaching EOL, and native ESM being used increasingly in Node projects (
type: module
inpackage.json
), including those which may also house browser code in need of testing, the apparent inability to use at least anindex.cjs
plugins file with Cypress seems rather problematic. (It complains about the extension; pointingpluginsFile
incypress.json
to a.cjs
file didn't work either; only switching to.js
works--or removingtype: module
but that causes problems for Node ESM execution.)(Please note that I'm not speaking about a
@babel/register
problem--I mean one simply can't use a cjs file at all.)Are there any plans (or workarounds) about this? Thanks!
The text was updated successfully, but these errors were encountered: