TypeError: (intermediate value).slice(...).reverse(...).flatmap is not a function when building app
Asked by DS:

`Hi there I'm trying to build and deploy my react app using bitbucket pipelines, I have built and deploy other ones, but for some reason this one is throwing me the following error `


    ----------------------

     Building the project ?????

    ----------------------

    yarn run v1.22.5

    $ env-cmd -f .env.development react-scripts build

    Creating an optimized production build...

    Failed to compile.

    TypeError: (intermediate value)(intermediate value)(intermediate value).slice(...).reverse(...).flatMap is not a function

    error Command failed with exit code 1.

    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

    Connection to $SERVER_ADRESS closed.

    ? Execution failed.

I can build the project locally, and I can actually manually deploy it as well when I connect to the server and run \`yarn run build:develop\`, but for some reason it breaks on the pipeline.  

Here is my \`bitbutcket-pipeline.yml\` for reference.

```
image: node:15.2.1

pipelines:

branches:

"{master,main}":

- step:

name: Deploying development ?

caches:

- nodeall

- yarn

script:

- echo 'Connecting to remote server to update repo'

- node --version

- npm --version

- pipe: atlassian/ssh-run:0.2.2

variables:

SSH_USER: $USER

SERVER: $SERVER_ADRESS

COMMAND: "cd smiling-scripts && bash admin-deploy-dev.sh"


definitions:

caches:

nodeall: ./node_modules

yarn: /usr/local/share/.cache/yarn
```

*** ** * ** ***

<br />

**EDIT: 23.08.2022**

Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)  

thanks for the reply. Yes that's the error I get from the command pipe: **atlassian/ssh-run:0.2.2 (and - pipe: atlassian/ssh-run:0.4.1**) now that I have changed it.

I don't get any errors when I connect to my server and build it manually. It builds without errors. Same as when I do it locally.

I can't understand why is only braking on the pipeline script. I have deleted the \`node_modules\` and reinstalled everything on the server but now I get the following error on the pipeline (so at least is not the same one ?, but still unable to build)

```

yarn run v1.22.5$ env-cmd -f .env.develop react-scripts build/home/$USER/$USER-admin-develop/node_modules/eslint-webpack-plugin/node_modules/jest-worker/build/index.js:110  _ending;         ^SyntaxError: Unexpected token ;    at Module._compile (internal/modules/cjs/loader.js:723:23)    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
```


Answers:
author: Theodora Boudale
body: Hi [@DS](/t5/user/viewprofilepage/user-id/4183757),

* You provided at the beginning of your post some output with an error. Is this output from the command **pipe: atlassian/ssh-run:0.2.2** of your yml file?  

* If you connect to your server as the same user in the variable $USER, switch to the directory *smiling-scripts,* and then execute *bash admin-deploy-dev.sh* , what output do you get?  
  Do you get the same output and error as in the pipe?

I would also suggest updating the version of the pipe to the newest one (0.4.1)

```
- pipe: atlassian/ssh-run:0.4.1
```

as you're using a version that is quite older.

Kind regards,  
Theodora

comments: author: DS
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) I updated my question. I tried to 'reply' to your message, but for some reason bitbucket keeps telling me 'You have posted a similar answer in the last few days please review your answer or change the text'


author: Theodora Boudale
body: Hi [@DS](/t5/user/viewprofilepage/user-id/4183757),

Thank you for the update. You mentioned that you don't get any errors when you connect to your server and build it manually.

Are you running the script *admin-deploy-dev.sh* located in *smiling-scripts* directory in order to build when you connect to your server?

It's not very clear from your reply if you run the same script on your server, or if e.g. you are running build commands directly without executing this specific script. Earlier in your post you mentioned that you ran \`yarn run build:develop\` on your server instead of executing the script.

Could you please let me know if the build is successful when you execute the script admin-deploy-dev.sh on the server? Just to check if the error seems to be specific to the script or not.

Kind regards,  
Theodora


author: Dante Solis
body: Hey [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)

So both things actually work in the server:

- if I run the build via the \`*admin-deploy-dev.sh\` script -\> the application builds*

*- if I run the build via \`yarn run build:develop\` -\> the application also builds.
<br />*

What I found out after trying and debugging more is that when I downgrade the \`react-scripts\` pkg to \`@v4.0.1\`, the application will build normally, however some styles and other stuff will not be available in the final product (this of course is not desirable)  

<br />

Right now I'm \`react-scripts @V.5.01\` when I leave as it is, it is when I get the following error:  

<br />

```
/home/$USER/$USER-admin-develop/node_modules/eslint-webpack-plugin/node_modules/jest-worker/build/index.js:110  _ending;         ^SyntaxError: Unexpected token ;    at Module._compile (internal/modules/cjs/loader.js:723:23)    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
```


author: Theodora Boudale
body: Hi [@Dante Solis](/t5/user/viewprofilepage/user-id/4815049),

Thank you for the info.

Could you please try one more thing, run the pipe with **MODE: 'script'** and **COMMAND: './smiling-scripts/admin-deploy-dev.sh'** and let me know if this works or if you still get errors (and if so, what errors)?

```
- pipe: atlassian/ssh-run:0.4.1
  variables:
    SSH_USER: $USER
    SERVER: $SERVER_ADRESS
    MODE: 'script'
    COMMAND: './smiling-scripts/admin-deploy-dev.sh'
```

Kind regards,  
Theodora


author: Dante Solis
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) sorry that it has taken me sol long to reply. I got busy with another project and work.  

At the end we gave up and then the project was taken from us.   

Thanks in any case for your reply.  


author: Theodora Boudale
body: Hi [@Dante Solis](/t5/user/viewprofilepage/user-id/4815049),

Thanks for the update. If you ever work on this again and need assistance, or if you need help with anything else, please feel free to reach out.

Kind regards,  
Theodora


author: Dante Solis
body: Thanks [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) ?


Tags: bitbucket-cloud

bitbucket-pipelines

cloud

react.js

ssh