exaco / laravel-octane-dockerfile

Production-ready Dockerfile for Laravel Octane (FrankenPHP, Swoole, RoadRunner) powered web services and microservices. Done right.
MIT License
590 stars 89 forks source link

Cannot find module @rollup/rollup-linux-x64-musl #62

Closed IgordeOliveira closed 7 months ago

IgordeOliveira commented 7 months ago

Thanks for the project! I'm learning a lot. I wanted to report an issue with the Vite build. I'm still trying to solve it, but here are the logs:

Laravel 10 + Filament

 => ERROR [laravel build 7/7] RUN npm run build                                                                                                                                                                                                0.7s 
------
 > [laravel build 7/7] RUN npm run build:
0.547
0.547 > build
0.547 > vite build
0.547
0.661 /var/www/html/node_modules/rollup/dist/native.js:87
0.661           throw new Error(
0.661                 ^
0.661
0.661 Error: Cannot find module @rollup/rollup-linux-x64-musl. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.  
0.661     at requireWithFriendlyError (/var/www/html/node_modules/rollup/dist/native.js:87:9)
0.661     at Object.<anonymous> (/var/www/html/node_modules/rollup/dist/native.js:96:76)
0.661     ... 3 lines matching cause stack trace ...
0.661     at Module._load (node:internal/modules/cjs/loader:1023:12)
0.661     at cjsLoader (node:internal/modules/esm/translators:356:17)
0.661     at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:305:7)
0.661     at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
0.661     at async ModuleLoader.import (node:internal/modules/esm/loader:329:24) {
0.661   [cause]: Error: Cannot find module '@rollup/rollup-linux-x64-musl'
0.661   Require stack:
0.661   - /var/www/html/node_modules/rollup/dist/native.js
0.661       at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
0.661       at Module._load (node:internal/modules/cjs/loader:985:27)
0.661       at Module.require (node:internal/modules/cjs/loader:1235:19)
0.661       at require (node:internal/modules/helpers:176:18)
0.661       at requireWithFriendlyError (/var/www/html/node_modules/rollup/dist/native.js:69:10)
0.661       at Object.<anonymous> (/var/www/html/node_modules/rollup/dist/native.js:96:76)
0.661       at Module._compile (node:internal/modules/cjs/loader:1376:14)
0.661       at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
0.661       at Module.load (node:internal/modules/cjs/loader:1207:32)
0.661       at Module._load (node:internal/modules/cjs/loader:1023:12) {
0.661     code: 'MODULE_NOT_FOUND',
0.661     requireStack: [ '/var/www/html/node_modules/rollup/dist/native.js' ]
0.661   }
0.661 }
0.661
smortexa commented 7 months ago

You're welcome! I'm glad it's helpful.

Just install @rollup/rollup-linux-x64-musl as a dev-dependency:

npm i @rollup/rollup-linux-x64-musl --save-dev

Or Add the following line to Dockerfile before installing NPM packages:

RUN npm i @rollup/rollup-linux-x64-musl --save-dev
IgordeOliveira commented 7 months ago

I understand. Does this dependency have any connection to this repository?

smortexa commented 7 months ago

No, It's about Vite, NPM, and probably Node.js base image.

IgordeOliveira commented 7 months ago

I managed to solve the issue by removing the "--no-optional" flag from both the "npm install" and "npm ci" commands. It turns out that this was a known bug in NPM, which has been documented in the following issue: npm/cli#4828.

COPY package*.json ./

RUN if [ -f $ROOT/package-lock.json ]; \
    then \
    npm ci --no-optional --loglevel=error --no-audit; \
    else \
    npm install --no-optional --loglevel=error --no-audit; \
    fi
smortexa commented 7 months ago

Thanks @IgordeOliveira. I made a PR to addressing this issue: #63