mathewparet's avatar

NPM Build failing on BitBucket Pipeline

I am trying to setup npm run build for my laravel application. Using Laravel 9 with Vite:

+ npm run build
> build
> vite build && vite build --ssr
vite v4.0.3 building for production...
transforming...
✓ 18 modules transformed.
Could not resolve "../../vendor/tightenco/ziggy/dist/vue.m" from "resources/js/app.js"
file: /opt/atlassian/pipelines/agent/build/resources/js/app.js
error during build:
RollupError: Could not resolve "../../vendor/tightenco/ziggy/dist/vue.m" from "resources/js/app.js"
    at error (file:///opt/atlassian/pipelines/agent/build/node_modules/rollup/dist/es/shared/rollup.js:1967:30)
    at ModuleLoader.handleInvalidResolvedId (file:///opt/atlassian/pipelines/agent/build/node_modules/rollup/dist/es/shared/rollup.js:23095:24)
    at file:///opt/atlassian/pipelines/agent/build/node_modules/rollup/dist/es/shared/rollup.js:23058:26

The pipeline throws the above error. Build works fine on my local machine.

My pipeline looks like this:

image: node:16

pipelines:
  branches:
    release/*:
      - step:
          name: Generate Production Build
          script:
            - npm install
            - npm run build
            - git add *
            - git commit -m "Generated production build"
            - git push
            - git flow finish $BITBUCKET_BRANCH
          caches:
            - node
0 likes
6 replies
Databee's avatar

This is an old post, but I have the same issue. Is there a solution for this? Has anyone been able to build a Laravel app with Inertiajs + Vite using BB pipeline?

cellen's avatar

@Databee I am running a Laravel 11 app with Inertia + Vue + Vite. I tried so many iterations of the pipeline script including the OPs with the same error occurring. I finally got it working, albeit a little messy using a php-fpm image instead of node (being manually installed in the step):

image: php:8.3-fpm

pipelines:
  branches:
    develop:
      - step:
          name: Run Tests
          services:
            - docker
          caches:
            - composer
            - node
          script:
            - apt-get update
            - apt-get install -y unzip libzip-dev libpng-dev zip git
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - docker-php-ext-configure zip
            - docker-php-ext-install zip bcmath pcntl gd
            - ln -f -s .env.pipelines .env
            - composer install --no-progress --no-suggest --prefer-dist --no-interaction
            - curl -sL https://deb.nodesource.com/setup_18.x | bash -  # Installing Node.js 18.x
            - apt-get install -y nodejs  # Installs both node and npm
            - php artisan key:generate
            - npm install
            - LARAVEL_BYPASS_ENV_CHECK=1 npm run build
            - php artisan test --parallel

Disclaimer: I know this question is a bit old, and while this works for my application, it doesn't feel like the most optimal way to go about it, so please use/reference at your own discretion. I'm going to look into creating/using a custom docker hub image to clean it up.

Please or to participate in this conversation.