-
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
Never uses esbuild to process cypress.config #22074
Comments
I did a lot of digging to explore solutions that will make Cypress as "batteries included" and "no config" as possible. Here's the current state of things, and my recommendations. ProblemWhen we load the user's The process is originally forked here: If users have require('./cypress.config.ts`)
// Or, neither works right now
import './cypress.config.ts') So, the problem is you cannot handle Ideal Solution: Use bundled
|
;(Module as ModuleClass)._load = function (request, parent, isMain) { | |
if (request === 'webpack' || request.startsWith('webpack/')) { | |
const resolvePath = require.resolve(request, { | |
paths: [webpack.importPath], | |
}) | |
debug('Webpack: Module._load resolvePath - %s', resolvePath) | |
return originalModuleLoad(resolvePath, parent, isMain) | |
} | |
return originalModuleLoad(request, parent, isMain) | |
} |
Recommendation
I think we should add support for ts-node/esm
, like suggested in #21939.
Oustanding Questions
I'm not entirely clear on when we'd use esbuild
over ts-node
. Is there something esbuild
does that ts-node/esm
does not? Right now this code path is never going to get hit, so the "try to use esbuild" concept is dead code - it's also incredibly misleading, since the system tests actually do use esbuild, since they are not system binary tests. If they were running against the binary, they'd fail.
We've used the integrated TypeScript transpiler at first, but it was becoming incredibly slow because of the amount of tests and dependencies we had. Once we switched to esbuild (using one of the two freely available npm plugins with minimal setup required), the preprocessing became extremely fast. I'd be happy to see esbuild getting integrated in a working manner, as it's much more performant (at least for us). But then again, bundling esbuild might lock users to a specific version? The current solution with copy&pasted boilerplate code for the esbuild-preprocessor is not ideal, but it works. Maybe this preprocessor-code-snippet could be integrated so you'd only need to pass the esbuild-options.. |
I agree, esbuild is the bomb. Rather than waiting for us to ship something official I think we can build something similar to https://github.com/cypress-io/cypress/tree/develop/npm/webpack-preprocessor but as I'd really like that, we can go way faster if we move away from ts-node to esbuild. I don't think this will be happening in core for a while, since many projects depend on how we use ts-node, but we can definitely build out something in the meantime as a plugin (which has access to all the internals you'd need anyway). How are you currently using esbuild with Cypress? |
I am interested, but honestly I don't have enough time to contribute seriously and the Cypress dev environment is pretty much impossible to install inside a corporate network (on my private PC it just worked). And after all I'm "just" a user... First I tried this https://github.com/bahmutov/cypress-esbuild-preprocessor , but I can't remember what didn't work, so I just tried the other one ever since https://github.com/sod/cypress-esbuild-preprocessor with esbuild 0.14.29. The setup is nothing more than already described:
If I recall correctly we used the webpack-preprocessor at one time but had compatibility issues because our app used webpack 5. I think it would be already a good practice to somehow maintain/fork this repo https://github.com/sod/cypress-esbuild-preprocessor and offer it as an official solution for preprocessing with esbuild. If I understood correctly Cypress 10 should preprocess TypeScript out-of-the-box without any further configuration? |
TypeScript should work out of the box! You might need to configure I agree should contribute to https://docs.cypress.io/guides/tooling/typescript-support, or just fork - the source is only around 40 LOC. I'd like to explore this, but I can't commit to a specific date/timeframe. |
Current behavior
Attempts to use esbuild but never actually does so successfully.
Details
EDIT: I removed the
esbuild
code path for now, as part of this PR #22118 where we usets-node/esm
to handle ES modules. You can reference that if/when we decided to work on this issue and revisit how we use esbuild in Cypress.On this part of the code:
cypress/packages/server/lib/plugins/child/run_require_async_child.js
Lines 120 to 122 in a264373
We do:
The problem is this will almost always fail - we check if
esbuild
is in the user'snode_modules
, viaprocess.cwd
(which is going to beprojectRoot
) but then requirebundle-require
from the binary'snode_modules
, which also assumesesbuild
is present in the binary'snode_modules
(which it never is - we do not shipesbuild
with the binary).For this to work, we would need to
esbuild
with the binary. It's around 8MB:Desired behavior
Either we ship
esbuild
or find some way to utilise the user'sesbuild
(cannot think of one). Or, just don't have this code (it's not doing anything).It's also not clear why we even include esbuild - Node supports native ES modules now, I'm not sure this is really necessary.
Test code to reproduce
DEBUG=cypress:life* yarn cypress open
esbuild
is available by looking in the user'snode_modules
, but then fails with "could not find module esbuild".Here is the output.
Larger output:
Cypress Version
10.0.2
Other
No response
The text was updated successfully, but these errors were encountered: