Pipelines build fails when webpack babel processing doesn't run on JS files

Issue #15803 resolved
François MUSY created an issue

We have a projet in node with webpack. If we run pipeline commands directly from the latest docker images of node:9-alpine, everything is Ok. In bitbucket, the pipeline fails.

The attached archive contains code to reproduce.

The relevant part of the error message is:

ERROR in ./src/index.js
Module parse failed: /opt/atlassian/pipelines/agent/build/src/index.js Unexpected token (9:10)
You may need an appropriate loader to handle this file type.
|    * Webpack fails with this declaration in pipelines
|    */
|   getProp = () => this.props;
| 
|   setProp(props) {
error An unexpected error occurred: "Command failed.
Exit code: 2
Command: sh
Arguments: -c ./node_modules/.bin/webpack
Directory: /opt/atlassian/pipelines/agent/build

Comments (6)

  1. Matt Ryall

    Wow, this took a bit of debugging. It isn't a bug in Pipelines, but part of your webpack configuration that doesn't work with the default working directory inside Pipelines.

    • The error in your log file indicates that the file isn't being processed as ES6, so the webpack execution fails because of the unrecognised arrow function on line 9 of src/index.js.
    • It isn't processed as ES6 because for some reason webpack isn't using the configured Babel loader when processing index.js.
    • After much head scratching, I finally worked out that the include/exclude rules in webpack.config.js must be wrong, so I made a more lenient include rule to confirm that was working, and then I spotted the problem in the exclude rule:
            include: path.resolve(__dirname, 'src'),
            exclude: /(node_modules|bower_components|build)/,
    

    The default build directory in Pipelines is /opt/atlassian/pipelines/agent/build/, so the last bit of the exclude pattern is excluding all files in your repository. This means none of your JS files will be processed by Babel, and you'll get this error.

    To fix it, you could simply remove |build from that regex, or set a more specific exclude pattern or path that will still allow the Pipelines build directory to be processed.

    In general, problems like these are not problems with Pipelines - we're just picking up a Docker container, putting your source code in it, and running your commands. So digging into how your own code works and runs is the way to get to the bottom of these things.

    Cheers,
    Matt

  2. François MUSY reporter

    Thanx for your reply @mryall_atlassian. I didn't think that the mount point in the container could be in conflict with our config.

    Cheers, François

  3. Hanyn Azman

    I merge my branch into different branch and when i go to piplines it has CONFLICT related to my webpack script. I did to build the file bfore i commit but stll doesnt work.

  4. Log in to comment