SyntaxError: Unexpected token at Yarn Run when deploying Laravel/Vue projekt with pipeline yml

SyntaxError: Unexpected token at Yarn Run when deploying Laravel/Vue projekt with pipeline yml

我正在尝试使用 .yml 脚本通过 bitbucket-pipeline 将我的项目部署到服务器。该项目有一个 laravel 后端与 PHP 7.4 和一个 Vue Js 前端。当前端使用 Yarn 运行 构建时会出现问题。构建过程正在我的同事和我的本地机器上使用完全相同的 yarn.lock 和 package.json,但不在管道中。本地我们也有相同的节点和yarn/npm版本。

这是我们的管道脚本:

    image:
    name: atlassian/default-image:2
definitions:
    steps:
        - step: &laravel-deploy
              name: Laravel Deployment
              caches:
                  - composer
              image: php:7.4.12-fpm
              script:
                  - mkdir -p "$REMOTE_PATH/$BITBUCKET_BUILD_NUMBER"
                  - export ROOT_DIR=$(pwd)
                  - mv * $REMOTE_PATH/$BITBUCKET_BUILD_NUMBER
                  - cd $REMOTE_PATH/$BITBUCKET_BUILD_NUMBER
                  - echo "install dependencies"
                  - echo "install Stuff"
                  - apt-get update && apt-get install -y unzip && apt-get install -y git && apt install -y openssh-client
                  - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=1.10.13
                  - if [ -z "$YARN_RUN" ]; then
                  - else
                  - apt-get update && apt-get install -y npm
                  - npm config set "@fortawesome:registry" https://npm.fontawesome.com/ && npm config set "//npm.fontawesome.com/:_authToken" $FA_TOKEN
                  - npm install --global yarn
                  - yarn install
                  - yarn run $YARN_RUN
                  - fi
                  - echo "build application"
                  - mkdir -p ~/.ssh
                  - echo $SSH_KEY > ~/.ssh/id_rsa.tmp # note: assumes base64 encoded ssh key without a passphrase
                  - base64 -d ~/.ssh/id_rsa.tmp > ~/.ssh/id_rsa
                  - chmod 600 ~/.ssh/id_rsa
                  - base64 ~/.ssh/id_rsa
                  - eval `ssh-agent -s`
                  - ssh-add ~/.ssh/id_rsa
                  - composer install $COMPOSER_OPTIONS
                  - php artisan config:cache
                  - if [ $OP_CAHCE -eq 1 ]; then
                  - php  artisan opcache:clear && php artisan opcache:compile --force
                  - fi
                  - mv -t $ROOT_DIR app artisan bootstrap config  public  resources routes storage vendor database
                  - cd $ROOT_DIR
                  - pipe: atlassian/ssh-run:0.2.3
                    variables:
                        SSH_USER: $SSH_USER
                        SERVER: $SSH_HOST
                        COMMAND: "rm -rf $REMOTE_PATH/$BITBUCKET_BUILD_NUMBER"
                  - echo "deploy to server"
                  - pipe: atlassian/rsync-deploy:0.4.0
                    variables:
                        USER: $SSH_USER
                        SERVER: $SSH_HOST
                        REMOTE_PATH: "$REMOTE_PATH/$BITBUCKET_BUILD_NUMBER"
                        LOCAL_PATH: "."
                        EXTRA_ARGS: --exclude='.*'
                  - echo "linking resources"
                  - pipe: atlassian/ssh-run:0.2.3
                    variables:
                        SSH_USER: $SSH_USER
                        SERVER: $SSH_HOST
                        COMMAND: "cd ${REMOTE_PATH} && rm -rf current &&  ls -tp | tail -n +6 | xargs rm -rf && ln -s \$(ls -tr | tail -n1 | xargs -0 realpath) current"


pipelines:
    default:
        - step:
              name: Analyze code
              script:
                  - pipe: sonarsource/sonarcloud-scan:1.1.0
    custom:
        deploy-to-testing:
            - step:
                  <<: *laravel-deploy
                  deployment: testing
    branches:
        staging:
            - step:
                  <<: *laravel-deploy
                  deployment: staging
        master:
            - step:
                  <<: *laravel-deploy
                  deployment: production

步骤中出现以下错误:- yarn 运行 $YARN_RUN。 这是错误消息的一部分,它总是 SyntaxError: Unexpected token :

+ yarn run $YARN_RUN
yarn run v1.22.10
$ cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js -no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
ERROR  Failed to compile with 58 errors8:13:28 AM

 error  in ./resources/assets/js/services/api/user.api.js

Syntax Error: Unexpected token (8:13)

   6 | export default class UserApi {
   7 |   
>  8 |   static url = "/users";
     |              ^
   9 | 
  10 |   /**
  11 |    * Get the user with ID.



 @ ./resources/assets/js/app.js 16:0-46
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/services/api/policy.api.js

Syntax Error: Unexpected token (9:13)

   7 |  */
   8 | export default class PolicyApi {
>  9 |   static url = "/policies";
     |              ^
  10 | 
  11 |   /**
  12 |    * Get the policy by given ID.



 @ ./node_modules/babel-loader/lib?{"cacheDirectory":true,"presets":[["env",{"modules":false,"targets":{"browsers":["> 2%"],"uglify":true}}]],"plugins":["transform-object-rest-spread",["transform-runtime",{"polyfill":false,"helpers":false}]]}!./resources/assets/js/pages/Lead/LeadsProvision/components/CommissionPaymentDateComponent/index.js 4:0-63
 @ ./resources/assets/js/pages/Lead/LeadsProvision/components/CommissionPaymentDateComponent/CommissionPaymentDateComponent.vue
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/services/api/customer.api.js

Syntax Error: Unexpected token (9:15)

   7 |  */
   8 | export default class CustomerApi {
>  9 |     static url = "/customers";
     |                ^
  10 | 
  11 |     /**
  12 |      * Get the customer by given ID.



 @ ./node_modules/babel-loader/lib?{"cacheDirectory":true,"presets":[["env",{"modules":false,"targets":{"browsers":["> 2%"],"uglify":true}}]],"plugins":["transform-object-rest-spread",["transform-runtime",{"polyfill":false,"helpers":false}]]}!./resources/assets/js/pages/Lead/LeadOverview/components/LeadActionComponent/index.js 3:0-67
 @ ./resources/assets/js/pages/Lead/LeadOverview/components/LeadActionComponent/LeadActionComponent.vue
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/services/api/lead.api.js

Syntax Error: Unexpected token (9:15)

   7 |  */
   8 | export default class LeadApi {
>  9 |     static url = "/leads";
     |                ^
  10 | 
  11 |     /**
  12 |      * Store a new customer for the lead.



 @ ./node_modules/babel-loader/lib?{"cacheDirectory":true,"presets":[["env",{"modules":false,"targets":{"browsers":["> 2%"],"uglify":true}}]],"plugins":["transform-object-rest-spread",["transform-runtime",{"polyfill":false,"helpers":false}]]}!./resources/assets/js/pages/Lead/LeadsProvision/components/PoliceLeadPaymentDateComponent/index.js 5:0-59
 @ ./resources/assets/js/pages/Lead/LeadsProvision/components/PoliceLeadPaymentDateComponent/PoliceLeadPaymentDateComponent.vue
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/components/SidebarComponent/index.js

Syntax Error: Unexpected token, expected , (10:27)

   8 |   computed: {
   9 |     ...mapState({
> 10 |       sidebarActive: (state: any) => state.sidebar.sidebarActive,
     |                            ^
  11 |     }),
  12 |   },
  13 |   methods: {



 @ ./resources/assets/js/components/SidebarComponent/SidebarComponent.vue 8:21-291
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/validators/currency-validator.js

Syntax Error: Unexpected token, expected , (11:32)

   9 |  * @returns {boolean}
  10 |  */
> 11 | const currencyValidator = (value: string) => {
     |                                 ^
  12 | 
  13 |   if (value || value === 0) {
  14 |     return (/^([0-9])+(,[0-9]{1,2})?$/).test(value);



 @ ./resources/assets/js/validators/index.js 11:0-53
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/validators/negative-currency-validator.js

Syntax Error: Unexpected token, expected , (11:40)

   9 |  * @returns {boolean}
  10 |  */
> 11 | const negativeCurrencyValidator = (value: string) => {
     |                                         ^
  12 | 
  13 |   if (value || value === 0) {
  14 |     return (/^-?([.0-9])+(,[0-9]{1,2})?$/).test(value);



 @ ./resources/assets/js/validators/index.js 12:0-70
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/filters/pretty-bytes-filter.js

Syntax Error: Unexpected token, expected , (11:45)

   9 |  * @returns {string}
  10 |  */
> 11 | export default function prettyBytesFilter(num: number) {
     |                                              ^
  12 |   if (typeof num !== 'number' || Number.isNaN(num)) {
  13 |     throw new TypeError(`Expected a number got ${typeof(num)}`);
  14 |   }



 @ ./resources/assets/js/filters/index.js 5:0-54
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/store/modules/customer-histories.js

Syntax Error: Unexpected token, expected , (12:30)

  10 |   },
  11 |   mutations: {
> 12 |     setCustomerHistory: (state: any, customerHistory: any) => {
     |                               ^
  13 |       state.customerHistory = customerHistory;
  14 |     },
  15 |     setCustomerHistories: (state: any, customerHistories: any) => {



 @ ./resources/assets/js/store/index.js 9:0-61
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/validators/insurer-validator.js

Syntax Error: Unexpected token, expected , (12:31)

  10 |  * @returns {boolean}
  11 |  */
> 12 | const insurerValidator = (value: any) => {
     |                                ^
  13 | 
  14 |   if (value) {
  15 |     return value.id !== null && value.id !== '';



 @ ./resources/assets/js/validators/index.js 13:0-51
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/validators/insurance-type-validator.js

Syntax Error: Unexpected token, expected , (12:35)

  10 |  * @returns {boolean}
  11 |  */
> 12 | const insurerTypeValidator = (value: any) => {
     |                                    ^
  13 | 
  14 |   if (value) {
  15 |     return value.id !== null && value.id !== '';



 @ ./resources/assets/js/validators/index.js 14:0-62
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/filters/concat-filter.js

Syntax Error: Unexpected token, expected , (12:42)

  10 |  * @returns {string}
  11 |  */
> 12 | export default function concatFilter(value: string, ...args: Array<string>) {
     |                                           ^
  13 |   if (args.length === 0) {
  14 |     return value;
  15 |   }



 @ ./resources/assets/js/filters/index.js 7:0-43
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/filters/concat-list-filter.js

Syntax Error: Unexpected token, expected , (12:54)

  10 |  * @returns {string}
  11 |  */
> 12 | export default function concatListFilter(listOfStrings: string[], delimiter = ', ') {
     |                                                       ^
  13 |   if (!Array.isArray(listOfStrings) || listOfStrings.length === 0) {
  14 |     return '';
  15 |   }



 @ ./resources/assets/js/filters/index.js 8:0-52
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/store/modules/user.js

Syntax Error: Unexpected token, expected , (13:20)

  11 |   },
  12 |   mutations: {
> 13 |     SET_USER: (state: any, newUser: any) => {
     |                     ^
  14 |       state.user = newUser;
  15 |     },
  16 |   },



 @ ./resources/assets/js/store/index.js 6:0-34
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/store/modules/policies.js

Syntax Error: Unexpected token, expected , (13:21)

  11 |   },
  12 |   mutations: {
> 13 |     setPolicy: (state: any, policy: Policy) => {
     |                      ^
  14 |       state.policy = policy;
  15 |     },
  16 |     setEditMode: (state: any, editMode: boolean) => {



 @ ./resources/assets/js/store/index.js 8:0-42
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/store/modules/customers.js

Syntax Error: Unexpected token, expected , (13:24)

  11 |   getters: {},
  12 |   mutations: {
> 13 |     setCustomers: (state: any, payload: any) => {
     |                         ^
  14 |       state.customers = payload.data.data;
  15 |     },
  16 |     setCustomer: (state: any, payload: any) => {



 @ ./resources/assets/js/store/index.js 7:0-44
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/js/validators/zip-validator.js

Syntax Error: Unexpected token, expected , (13:27)

  11 |  * @returns {boolean}
  12 |  */
> 13 | const zipValidator = (value: string) => {
     |                            ^
  14 |   const pattern = XRegExp('^[0-9]{5}$');
  15 |   return pattern.test(value);
  16 | };

这是我们的 package.json:

{
  "private": true,
  "version": "0.0.1",
  "name": "acm",
  "scripts": {
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch-poll": "npm run watch -- --watch-poll",
    "cypress:open": "cypress open",
    "cypress:run": "cypress run",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "prod": "npm run production",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "docs:generate": "node_modules/.bin/jsdoc resources/assets/js/ -c jsdoc.conf.json -t node_modules/docdash -r -d docs",
    "unit": "cross-env NODE_ENV=testing karma start --code-coverage"
  },
  "dependencies": {
    "@fortawesome/fontawesome-free": "^5.4.0",
    "@fortawesome/fontawesome-pro": "^5.4.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.6",
    "@fortawesome/free-brands-svg-icons": "^5.4.0",
    "@fortawesome/pro-light-svg-icons": "^5.4.0",
    "@fortawesome/pro-regular-svg-icons": "^5.4.0",
    "@fortawesome/pro-solid-svg-icons": "^5.4.0",
    "@fortawesome/vue-fontawesome": "0.1.1",
    "axios": "^0.18",
    "bootstrap": "^4.0.0",
    "bootstrap-vue": "^2.0.0-rc.9",
    "lodash": "^4.17.4",
    "moment": "^2.22.2",
    "node-sass": "^4.11.0",
    "password-generator": "^2.2.0",
    "raven-js": "^3.26.4",
    "sass-loader": "^7.1.0",
    "vee-validate": "2.0.9",
    "vue": "^2.5.13",
    "vue-clickaway": "^2.2.2",
    "vue-context": "^3.2.0",
    "vue-moment": "^3.1.0",
    "vue-multiselect": "2.0.3",
    "vue-perfect-scrollbar": "^0.1.0",
    "vue-router": "^3.0.1",
    "vue-simple-spinner": "^1.2.8",
    "vue2-datepicker": "^2.0.4",
    "vue2-filters": "^0.3.0",
    "vuetable-2": "^1.7.2",
    "vuex": "^3.0.1",
    "xregexp": "^4.2.0"
  },
  "devDependencies": {
    "@vue/test-utils": "^1.0.0-beta.25",
    "axios-mock-adapter": "^1.15.0",
    "babel-eslint": "^8.2.3",
    "babel-plugin-syntax-flow": "^6.18.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-flow-strip-types": "^6.22.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "cross-env": "^5.1",
    "cypress": "3.1.0",
    "docdash": "^0.4.0",
    "eslint": "^4.19.1",
    "eslint-config-airbnb-base": "^13.0.0",
    "eslint-plugin-cypress": "^2.0.1",
    "eslint-plugin-flowtype-errors": "^3.6.0",
    "eslint-plugin-html": "^4.0.3",
    "eslint-plugin-import": "^2.13.0",
    "eslint-plugin-vue": "^4.5.0",
    "flow-bin": "^0.73.0",
    "jasmine-core": "^3.1.0",
    "jsdoc": "3.5.5",
    "jsdoc-babel": "^0.4.0",
    "karma": "^2.0.2",
    "karma-babel-preprocessor": "^7.0.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-coverage-istanbul-reporter": "^2.0.1",
    "karma-firefox-launcher": "^1.1.0",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^1.1.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-spec-reporter": "^0.0.32",
    "karma-webpack": "^3.0.0",
    "laravel-mix": "^2.0",
    "vue-template-compiler": "^2.5.13",
    "webpack-livereload-plugin": "^1.0.0"
  }
}

我们尝试了很多解决方案,例如更新 babel 包、编辑 babelrc 文件或尝试使用不同的包管理器安装包。但到目前为止没有任何效果。

对于遇到同样问题的人,我们找到了答案。问题是以下命令:

- mv * $REMOTE_PATH/$BITBUCKET_BUILD_NUMBER

mv 移动所有不以 . 开头的文件。因为 babelrc 文件以 . 开头,所以它没有被移动。没有这个文件,插件无法加载,编译失败。我们将命令更改为:

mv * .babelrc $REMOTE_PATH/$BITBUCKET_BUILD_NUMBER

一切正常。