-
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
Cypress and Yarn 2 PNP support #8008
Comments
@bahmutov @jennifer-shehane please take a look at this issue, this is a huge blocker since there's no known workaround... Yarn 2.1.1 has been recently released, which means it's time to support it. Is there anything I can help? @arcanis I was trying to find a way to import |
@kirill-konshin you can open a PR with at least some work showing what is going on in CLI when Yarn v2 is used to install Cypress |
@bahmutov here you go https://github.com/kirill-konshin/cypress-test-tiny-yarn-pnp/pull/1/files (branch bug), monorepo is actually not needed, since none of PNP resolutions work. Just run $ yarn install
$ yarn test And get an error:
|
@bahmutov Any updates? We're completely blocked for almost a month, are there any workarounds or hacks? |
We did not work on this issue, since it has low priority overall. If you know how to make Cypress NPM module play nicely with Yarn 2, you can open a PR into Cypress with the fix. PS: The error above seems to indicate a problem not with the Cypress itself, but with another plugin, no? |
@bahmutov I wish I could make a PR, but I am not familiar with Cypress codebase at all. I know that Yarn 2 is shipped with a set of tools https://next.yarnpkg.com/advanced/pnpapi and https://next.yarnpkg.com/advanced/pnpify that can be used to resolve packages. Superficially it looks like Cypress is creating a new Node (or Browser) context, which is not aware of PNP resolution (unlike the main process). The error above is a Cypress problem because it would happen with ANY plugin, since it is related to resolution algorithm in general. Given that this issue has ben linked from another issue, there is some traction, and Yarn 2 is already public, so please consider raising the priority. |
@bahmutov any updates? |
@bahmutov is there anything else that I can do to speed it up? Do you have any ETA? |
I would do a pull request with the solution if yarn 2 is a high priority for your needs
…Sent from my iPhone
On Sep 1, 2020, at 16:11, Kirill Konshin ***@***.***> wrote:
@bahmutov is there anything else that I can do to speed it up? Do you have any ETA?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Like I said before, I’m not familiar with Cypress architecture and this bug seems to be buried quite deep, in the code where cypress resolves dependencies. Pnp has to be injected there, or their resolution has to be used. If you can point out the direction or provide a fix - it would be much better. |
But isn’t it just the part of Cypress CLI which is quite limited?
…Sent from my iPhone
On Sep 1, 2020, at 16:24, Kirill Konshin ***@***.***> wrote:
Like I said before, I’m not familiar with Cypress architecture and this bug seems to be buried quite deep, in the code where cypress resolves dependencies. Pnp has to be injected there, or their resolution has to be used. If you can point out the direction or provide a fix - it would be much better.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
It is definitely not part of CLI, it is the part that involves browser, because it all works in CLI. Please take a closer look at bug description: it works for |
For reference see issues: - cypress-io/cypress#6377 - cypress-io/cypress#8008
Adding the pnp-webpack-plugin is needed until cypress is using webpack 5. const webpackPreprocessor = require('@cypress/webpack-preprocessor');
const PnpWebpackPlugin = require('pnp-webpack-plugin');
module.exports = (on) => {
const options = {
webpackOptions: {
resolve: {
plugins: [
PnpWebpackPlugin
]
},
resolveLoader: {
plugins: [
PnpWebpackPlugin.moduleLoader(module)
]
}
},
watchOptions: {}
};
on('file:preprocessor', webpackPreprocessor(options));
}; |
@marcneander it did work, thanks a lot! Totally makes sense why. |
Cypress should support built-in yarn 2 (PNP algorithm) and it's really important. |
+1 for this please. I'm currently completely unable to write my integration tests or any code related to it in TypeScript in my otherwise entirely TypeScript based yarn2/pnp project. |
The pnp-webpack-plugin did not work for me, however... I had luck in a TypeScript + Cypress project doing the following in the Cypress plugins/index.js file: const deepmerge = require("deepmerge");
const path = require("path");
module.exports = (on, config) => {
// deep-merge config with the actual reporter
config = deepmerge(config, {
reporter: require(
require(path.join(config.projectRoot, ".pnp.js")).resolveToUnqualified("cypress-multi-reporters", __filename)
),
reporterOptions: {
... // put reporter options here
}
})
... // other plugin config
The key being yarn pnp API's |
As per #15241, this is also broken for resolving typescript cypress config:
/// <reference types="cypress" />
const config: Cypress.PluginConfig = (on, config) => {
// plugin config
};
export default config; Fails with various errors due to it being run without transpilation. This is not in a monorepo configuration. |
Has anyone succeeded with using PnpWebpackPlugin? I am also blocked with yarn 2 implementation |
Webpack 5 has built in pnp support. does Cypress have plan to switch default webpack preprocessor to webpack 5? |
Is there any movement on this PR? It's pretty annoying that this is the only package that forces us to use |
@AaronBuxbaum You can track the currently opened PR here: #15623 Although this PR will not address all of the issues preventing Cypress from fully working with Yarn 2. |
If anyone else comes across this, managed to get this to work by just making sure that the PnP plugin gets added to the webpack config that Cypress uses. This works with cypress@7.3.0 using PnP with yarn workspaces. The following just needs to get added to you module.exports = (on) => {
// You need to use your PnP file to resolve files. The following is just the path that traverses up to where my PnP file is in our repo root.
const pnp = require('../../../../.pnp.js');
// I couldn't find this documented, but this appears to monkey-patch require and do all the other necessary things to get PnP working
pnp.setup();
// This is where we'll be resolving packages from. In this case, it is a workspace package we have named, but using a relative path here should work as well to resolve from a specific folder.
const targetModule = '@mypackages/package';
// We need to patch the webpack config that cypress uses (which is v4 which needs a plugin for PnP support)
const webpackPreprocessor = require(pnp.resolveToUnqualified('@cypress/webpack-preprocessor', targetModule));
const PnpWebpackPlugin = require(pnp.resolveToUnqualified('pnp-webpack-plugin', targetModule));
const options = {
webpackOptions: {
resolve: {
plugins: [
PnpWebpackPlugin
]
},
resolveLoader: {
plugins: [
PnpWebpackPlugin.moduleLoader(module)
]
}
},
watchOptions: {}
};
on('file:preprocessor', webpackPreprocessor(options));
}; You also may need to add |
Thanks! I've been looking for a solution for this for a while, I got it working with this example. |
Hello!
I'm not sure exactly what you mean by the "targetModule". With pnp, you'll
notice that modules are stored in a different location than
"node_modules/[thing]". So when using pnp, require("thing") gets translated
to require("/some/long/cached/path/of/the/thing/module").
The function resolveUnqualified essentially does that transformation for
you. It returns the long "/some/long/cached/path/of/the/thing/module".
Webpack 5 handles this for you so you don't need to worry about it.
However, something about the Cypress / Webpack 5 integration isn't complete
/ doesn't do this. So in my example, I manually go and get the location of
where pnp stored cypress-multi-reporters so that it can be used.
Hope that helps,
Tom
…On Tue, Jun 29, 2021 at 11:20 PM Chris Castillo ***@***.***> wrote:
resolveToUnqualified
I'm currently trying to implement your solution. Thank you for doing all
this work. But I have a question if you have the time. Do you know what the
targetModule resolves to? I have tried reading Yarn PNP docs, but it just
does not make sense to me.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#8008 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACXQICIILMEPQT4CVSAHZC3TVKEPRANCNFSM4O5EC3OA>
.
|
cc @merceyz this is the cypress issue i was talking about. Cypress is using a forked process (from its electron app) to do compilation through webpack. I think in order to make cypress compatible with yarn pnp natively . We need to either:
|
The code for this is done in cypress-io/cypress#17335, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior:
In Yarn 2 monorepo I have a package
a
and tests in packageb
.When I do
It works as expected.
But
Fails with error:
Looks like Yarn's Plug'n'play file
.pnp.js
is not present in second (commands) context.Desired behavior:
Require of monorepo packages should work.
The text was updated successfully, but these errors were encountered: