Skip to content
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

browserslist extends not working with cypress #2983

Open
marcneander opened this issue Dec 23, 2018 · 19 comments
Open

browserslist extends not working with cypress #2983

marcneander opened this issue Dec 23, 2018 · 19 comments
Labels
E2E Issue related to end-to-end testing existing workaround stage: needs investigating Someone from Cypress needs to look at this Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: unexpected behavior User expected result, but got another

Comments

@marcneander
Copy link

Steps to reproduce

I'm using browserslist like so many others. I have my browserslist config published as an npm package and use it like this in my package.json:

"browserslist": [
    "extends @marcneander/browserslist-config"
],

When running yarn run cypress run with only your example tests I get this error (for all tests):

Error: [BABEL] /Users/marc/src/marcneander/marcneander.io/cypress/integration/examples/actions.spec.js: Cannot find module '@marcneander/browserslist-config' (While processing: "/Users/marc/Library/Caches/Cypress/3.1.3/Cypress.app/Contents/Resources/app/packages/server/node_modules/@babel/preset-env/lib/index.js") while parsing file: /Users/marc/src/marcneander/marcneander.io/cypress/integration/examples/actions.spec.js

Versions

Cypress: 3.1.3
Mac OS: 10.14.2
Node: 11.4.0

@jimmibond
Copy link

have you validated JSON data? you can use online tools like https://jsonformatter.org

@marcneander
Copy link
Author

@jimmibond Not sure where you think I might have invalid JSON but the package.json file is valid JSON and the package @marcneander/browserslist-config is exporting a browserslist array https://github.com/marcneander/browserslist-config/blob/master/index.js.

https://github.com/browserslist/browserslist#shareable-configs

@chodorowicz
Copy link

I have exactly same problem with my project.

@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Jan 29, 2019
@christophehurpeau
Copy link
Contributor

Same issue. There is an option in @babel/preset-env you could use: ignoreBrowserslistConfig

christophehurpeau added a commit to christophehurpeau/cypress that referenced this issue Mar 11, 2019
fixes cypress-io#2983

But perhaps it would be better to specify a target ?
@cypress-bot cypress-bot bot added stage: work in progress and removed stage: needs investigating Someone from Cypress needs to look at this labels Mar 11, 2019
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: work in progress stage: ready for work The issue is reproducible and in scope and removed stage: work in progress stage: needs review The PR code is done & tested, needs review labels Mar 21, 2019
@chrisbreiding
Copy link
Contributor

You can modify the options for @babel/preset-env like so:

const browserify = require('@cypress/browserify-preprocessor')

module.exports = (on) => {
  const options = browserify.defaultOptions
  const envPreset = options.browserifyOptions.transform[1][1].presets[0]
  options.browserifyOptions.transform[1][1].presets[0] = [envPreset, { ignoreBrowserslistConfig: true }]

  on('file:preprocessor', browserify(options))
}

@marcneander
Copy link
Author

Not sure this is solved by doing the above workaround.

@jennifer-shehane jennifer-shehane removed the stage: ready for work The issue is reproducible and in scope label Mar 29, 2019
@jennifer-shehane
Copy link
Member

@marcneander The above comment's workaround is intended to fix this issue. Please comment if you have tried the solution and are still experiencing this problem.

@marcneander
Copy link
Author

@jennifer-shehane Not sure I agree.

I'm using browserslist in a documented way and when I do I cannot use cypress without the above workaround. A fix would be to resolve the browserslist extends in the correct way.

@christophehurpeau
Copy link
Contributor

christophehurpeau commented Apr 2, 2019

Tried this plugin using only chrome as a browser and it works:

'use strict';

const browserify = require('@cypress/browserify-preprocessor');

module.exports = (on, config) => {
  let customBrowserify;

  on('before:browser:launch', (browser = {}, args) => {
    const options = browserify.defaultOptions;
    const envPreset = options.browserifyOptions.transform[1][1].presets[0];
    options.browserifyOptions.transform[1][1].presets[0] = [
      envPreset,
      { ignoreBrowserslistConfig: true, targets: { [browser.name]: browser.majorVersion } },
    ];
    customBrowserify = browserify(options);
  });

  on('file:preprocessor', (file) => customBrowserify(file));
};

I think however it should be included in cypress.

@anthonytranDev
Copy link

anthonytranDev commented May 22, 2019

@jennifer-shehane

Please can you can you Reopen this issue, as it's preferable that a fix is found. As many applications utilise extends @browserlist. For there web applications. Thanks!

@PaulMaly
Copy link

PaulMaly commented Sep 1, 2019

The issue is still relevant! We can't use browserlist configs in an appropriate way with cypress right now. Any workarounds are ridiculous in this case, it should be a part of cypress itself.

@skjnldsv
Copy link

@jennifer-shehane please reconsider again. This break any good testing setup. Something as used as browserlist extends should not require some weird hack to make it work :)
Thanks for the amazing job so far!

@coderica
Copy link

coderica commented Sep 30, 2019

@chrisbreiding @jennifer-shehane we just ran into this issue in our project. As several others have already mentioned, this is broken in Cypress and therefore this issue is not actually closed. Please reopen.

Edit: for those watching, I've gone ahead and opened #5252 since this one seems to have gone stale.

@leepowelldev
Copy link

Agree with others - this should be baked into Cypress without requiring workarounds

@chrisbreiding
Copy link
Contributor

I looked into this a bit. I haven't figured out a solution, but here are my notes for documentation's sake:

  • This failure occurs here when browserslist tries to require the extended config (e.g. @company/browserslist-config).
  • It only occurs when using the browserify preprocessor that's required by default in Cypress. Installing the browserify preprocessor in an individual project and wiring it up in the plugins file will fix the issue, even without configuring it to ignore browserslists (see new workaround below).
  • This leads me to believe that the root of the issue is the user's project being disconnected from Cypress/electron/node's lookup paths.
  • In order to bridge that disconnect, I tried using the browserify paths option to include the project path, so it would look for node modules there, but it didn't seem to work.

Need to do more research to find a fix that can be baked into Cypress and/or the browserify preprocessor. For now, here is a simpler workaround than the one I posted above that doesn't require ignoring browserslist:

  • Install the browserify preprocessor: npm install --save-dev @cypress/browserify-preprocessor
  • Add this to your plugins file:
    const browserify = require('@cypress/browserify-preprocessor')
    
    module.exports = (on) => {
      on('file:preprocessor', browserify())
    } 

@reintroducing
Copy link

@chrisbreiding I also just ran into this issue and it seems like the last update was back on January 3rd by you. I don't mean to +1 but this has gone stale/quiet and wanted to revive this to see if any headway has been made on this from the Cypress side? There have been many releases since that date and this issue remains open. It would be great to get an official update here as I agree with the others, this should be baked into Cypress and not require a workaround since this is the properly documented usage of external Browserslist configs.

@cypress-bot cypress-bot bot added the stage: needs investigating Someone from Cypress needs to look at this label Jul 8, 2020
@havenchyk
Copy link

any reason to use browserify-preprocessor instead of webpack-preprocessor?

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 18, 2023
@skjnldsv
Copy link

Still happens

@nagash77 nagash77 added existing workaround E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed stale no activity on this issue for a long period labels May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing existing workaround stage: needs investigating Someone from Cypress needs to look at this Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: unexpected behavior User expected result, but got another
Projects
None yet
Development

No branches or pull requests