question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to extend cypress webpack.config

See original GitHub issue

I was trying to migrate my project to monorepo to the fresh generated angular nx workspace, with libs and few apps. Currently we use cypress 3 with custom webpack configuration which looks more or less like this

const path = require("path");
module.exports = {
    resolve: {
        alias: {
            "@xyz/ng-shared": path.join(__dirname, "../node_modules/@xyz/ng-shared"),
            "moment": path.join(__dirname, "../node_modules/moment"),
        },
        extensions: ['.ts', '.js'],
        modules: ['node_modules'],
        symlinks: true
    },
    module: {
        rules: [
            {
                test: /\.ts?$/,
                use: [
                    {
                        loader: 'ts-loader',
                        options: {
                            transpileOnly: true
                        }
                    }
                ]
            }
        ]
    }
};

We have ng-shared npm package, that hase some cypress components written in typescript and publish to private npm registry as is (without transpilation, raw .ts files are included in bundled package)

The webpack config from above adds ability to transpile and properly load those files when importing it in the test suite.

When using default nx cypress configuration I’m getting error like this as soon as I try to import some .ts file from node_modules.

Module parse failed: Unexpected token (7:33)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|  */
| 
> export class DatePickerComponent implements CypressComponent {

I see that nx configuration looks like this:

const {preprocessTypescript} = require('@nrwl/cypress/plugins/preprocessor');

module.exports = (on, config) => {
    // `on` is used to hook into various events Cypress emits
    // `config` is the resolved Cypress config

    // Preprocess Typescript file using Nx helper
    on('file:preprocessor', preprocessTypescript(config));
};

is it possible to somehow say that I want to include particular folder from node_modules to process it via typescript loader? I saw the source code of this plugin and it is using webpack config under the hood but I don’t know how would I extend it.

I was looking for some help on the slack, but didn’t get correct answers so I’m trying here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
FrozenPandazcommented, Nov 6, 2020

The second parameter of preprocessTypescript is a function that updates the webpack configuration.

customizeWebpackConfig?: (webpackConfig: any) => any

Nx calls the function that you provide with the webpackConfig that we would use by default and you can add to it or replace it entirely and return the configuration that you want. 🎉

It would be nice to get some docs for this 😄

0reactions
barbados-clemenscommented, Aug 25, 2022

@naticaceres Cypress comes with a webpack preprocessor plugin already. you just use plugins file (or setupNodeEvents for cypress 10+)

more info here: https://docs.cypress.io/api/plugins/preprocessors-api

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to extend Webpack config in Cypress 10+ - Stack Overflow
I'm trying to extend the Webpack config in Cypress 10.8.0, but the only documentation I could find refers to the "legacy plugin file": ......
Read more >
Preprocessors API - Cypress Documentation
A preprocessor is the plugin responsible for preparing a support file or a test file for the browser. A preprocessor could transpile your...
Read more >
The No Tears Cypress Setup - Medium
Cypress has a node process that can be used to extend some of its functionality. This includes configuring file pre-processors or loading ...
Read more >
@cypress/webpack-preprocessor - npm
Cypress preprocessor for bundling JavaScript via webpack. Latest version: 5.16.0, last published: 6 days ago.
Read more >
TypeScript - webpack
Let's set up a configuration to support JSX and compile TypeScript down to ... Make sure to avoid setting module to "CommonJS", or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found