FROM node:20-alpine as build RUN apk update && apk add --no-cache build-base gcc…
- User
FROM node:20-alpine as build RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1
WORKDIR /opt/app
COPY package.json yarn.lock ./ COPY src/plugins/ src/plugins/
RUN yarn global add node-gyp RUN yarn config set network-timeout 600000 -g && yarn install
COPY src/ src/ COPY public/ public/ COPY database/ database/ COPY config/ config/ COPY tsconfig.json ./ COPY favicon.png ./ COPY tsconfig.json ./
RUN yarn --cwd src/plugins/fdc-duplicate build RUN yarn --cwd src/plugins/fdc-material-symbols build
RUN yarn build
FROM node:20-alpine RUN apk add --no-cache vips-dev
WORKDIR /opt/app
COPY --from=build /opt/app ./ COPY docker/entrypoint.sh ./ COPY docker/healthcheck.js ./
RUN chmod +x entrypoint.sh
EXPOSE 1337 ENTRYPOINT ["./entrypoint.sh"]
{ "version": "0.0.0", "keywords": [], "type": "commonjs", "exports": { "./package.json": "./package.json", "./strapi-admin": { "source": "./admin/src/index.js", "import": "./dist/admin/index.mjs", "require": "./dist/admin/index.js", "default": "./dist/admin/index.js" }, "./strapi-server": { "source": "./server/src/index.js", "import": "./dist/server/index.mjs", "require": "./dist/server/index.js", "default": "./dist/server/index.js" } }, "files": [ "dist" ], "scripts": { "build": "strapi-plugin build", "watch": "strapi-plugin watch", "watch:link": "strapi-plugin watch:link", "verify": "strapi-plugin verify" }, "dependencies": { "@strapi/design-system": "^2.0.0-rc.23", "@strapi/icons": "^2.0.0-rc.22", "react-intl": "^6.6.2" }, "peerDependencies": { "@strapi/strapi": "^5.17.0", "@strapi/sdk-plugin": "^5.3.2", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.30.1", "styled-components": "^6.1.19" }, "strapi": { "kind": "plugin", "name": "fdc-duplicate", "displayName": "FDC Duplicate Button", "description": "Satrpi plugin for creating duplicate of entries" }, "name": "fdc-duplicate", "description": "Satrpi plugin for creating duplicate of entries", "license": "MIT", "author": "tetiana" }
=> [strapi build 12/17] COPY tsconfig.json ./ 0.1s => [strapi build 13/17] COPY favicon.png ./ 0.1s => [strapi build 14/17] COPY tsconfig.json ./ 0.1s => ERROR [strapi build 15/17] RUN yarn --cwd src/plugins/fdc-duplicate build 0.6s
[strapi build 15/17] RUN yarn --cwd src/plugins/fdc-duplicate build: 0.470 yarn run v1.22.22 0.509 $ strapi-plugin build 0.521 /bin/sh: strapi-plugin: not found 0.529 error Command failed with exit code 127. 0.530 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
failed to solve: process "/bin/sh -c yarn --cwd src/plugins/fdc-duplicate build" did not complete successfully: exit code: 127
- Assistant
Okay, the error message
/bin/sh: strapi-plugin: not foundis the key.This means that when Yarn tried to execute the
buildscript defined in yoursrc/plugins/fdc-duplicate/package.json("build": "strapi-plugin build"), the commandstrapi-plugincould not be found in the container's PATH.Why did this happen? The
strapi-plugincommand is provided by the@strapi/sdk-pluginor similar Strapi development SDK package. When you runyarn buildwithin the plugin's directory (src/plugins/fdc-duplicate), Yarn looks for executable scripts innode_modules/.bin/inside that directory (or in parent directories up to the project root).Your Dockerfile installs the root project dependencies (
yarn installat/opt/app), but it doesn't explicitly install the dependencies for the plugin itself located atsrc/plugins/fdc-duplicate. Even though@strapi/sdk-pluginmight be apeerDependencyor a dependency of the main Strapi project, the plugin'sbuildscript needs to find it relative to the plugin's context, typically in its ownnode_modules.The Solution: You need to install the dependencies for the plugin before you try to build it. You can do this by running
yarn installspecifically within the plugin's directory after you've copied the plugin's code (which includes itspackage.jsonand potentiallyyarn.lock).Here's the corrected Dockerfile:
FROM node:20-alpine as build RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1 WORKDIR /opt/app # 1. Copy root dependency files first to leverage caching COPY package.json yarn.lock ./ # 2. Install root dependencies # Removed global node-gyp as it's often handled by dependency installation RUN yarn config set network-timeout 600000 -g && yarn install # 3. Copy all application code (including src/plugins, config, etc.) # This ensures plugin package.json and code are present COPY . . # 4. Install dependencies *for each plugin* before building them # This step is crucial for finding 'strapi-plugin' RUN yarn install --cwd src/plugins/fdc-duplicate RUN yarn install --cwd src/plugins/fdc-material-symbols # Assuming this one also needs deps # 5. Build each plugin individually RUN yarn --cwd src/plugins/fdc-duplicate build RUN yarn --cwd src/plugins/fdc-material-symbols build # 6. Run the main application build RUN yarn build # --- Final Stage --- FROM node:20-alpine # Install only runtime dependencies required by the app (like libvips) RUN apk add --no-cache vips-dev WORKDIR /opt/app # Copy build artifacts and necessary scripts from the build stage COPY --from=build /opt/app ./ # Ensure entrypoint script is executable RUN chmod +x entrypoint.sh EXPOSE 1337 ENTRYPOINT ["./entrypoint.sh"]Explanation of Changes:
- Consolidated
COPY: Instead of multipleCOPYcommands forsrc,public,database, etc., a singleCOPY . .after the rootyarn installis used. This copies the entire source code, including thesrc/plugins/directories with theirpackage.jsonfiles. This is a more common and often more cache-efficient pattern after dependency installation. - Added Plugin
yarn install: The critical fix is addingRUN yarn install --cwd src/plugins/fdc-duplicate(and for the other pluginfdc-material-symbols). This command changes the directory to the plugin's source folder (/opt/app/src/plugins/fdc-duplicate) and runsyarn installthere. This installs the plugin's own dependencies (including@strapi/sdk-pluginlikely via peer dependencies or devDependencies) intosrc/plugins/fdc-duplicate/node_modules/. - Plugin Build After Install: Now, when
RUN yarn --cwd src/plugins/fdc-duplicate buildis executed, Yarn can find thestrapi-pluginexecutable in the newly creatednode_modules/.bin/directory within the plugin's folder. - Entrypoint/Healthcheck Copy: Added
COPY . .in the build stage assumesdocker/entrypoint.shanddocker/healthcheck.jsare at the root of your build context. The final stage then copies all of/opt/appfrom the build stage, including these scripts.
Apply these changes to your
Dockerfileand try building again. This should resolve the "strapi-plugin: not found" error. - Consolidated
- User
✖ Building admin panel 7.799 [ERROR] There seems to be an unexpected error, try again with --debug for more information 7.799 7.803 ┌──────────────────────────────────────────────────────────────────────────────┐│ ││ Could not resolve ││ "../../src/plugins/fdc-duplicate/./dist/admin/index.mjs" from ││ ".strapi/client/app.js"
││ file: /opt/app/.strapi/client/app.js ││ at getRollupError ││ (file:/// opt/app/node_modules/rollup/dist/es/shared/parseAst.js:397:41) ││ at error ││ (file:///opt/app/node_modules/rollup/dist/es/shared/parseAst.js:393:42) ││ at ModuleLoader.handleInvalidResolvedId (file:///opt/app/node_modules/ro ││ llup/dist/es/shared/node-entry.js:21167:24)
││ at file:///opt/app/node_modules/rollup/dist/es/shared/node-entry.js:2112 ││ 7:26 ││
│└──────────────────────────────────────────────────────────────────────────────┘ 7.860 error Command failed with exit code 1. - Assistant
Okay, the previous error (
strapi-plugin: not found) was resolved by runningyarn installwithin the plugin directory before attempting to build the plugin.Now, you're facing a new error during the main
yarn buildstep, specifically when building the admin panel:Could not resolve "../../src/plugins/fdc-duplicate/./dist/admin/index.mjs" from ".strapi/client/app.js" file: /opt/app/.strapi/client/app.jsExplanation of the Error:
- Context: This error occurs during the main Strapi build process (
yarn buildin/opt/app), which includes bundling the admin panel. - Source: The file causing the issue is
/opt/app/.strapi/client/app.js. This file is automatically generated by Strapi during the build process. It likely acts as an entry point or an intermediate file that ties together the core Strapi admin code and any discovered plugins. - Problem: Strapi's bundler (likely Rollup, as hinted by the error trace) is trying to import a module from the path
../../src/plugins/fdc-duplicate/./dist/admin/index.mjsrelative to/opt/app/.strapi/client/app.js. - Path Resolution: Let's trace that path:
- Starting from
/opt/app/.strapi/client/ ../goes up to/opt/app/.strapi/../goes up to/opt/app/src/plugins/fdc-duplicate/./dist/admin/index.mjs- The path resolves to
/opt/app/src/plugins/fdc-duplicate/dist/admin/index.mjs.
- Starting from
- The Core Issue: The bundler cannot find the file at
/opt/app/src/plugins/fdc-duplicate/dist/admin/index.mjs.
Why might this happen?
- Timing/Race Condition (Less likely here): The main build process starts before the plugin's build process finishes or the files are fully written. (Unlikely in a sequential Dockerfile
RUNcommand). - Incorrect Path in Plugin
package.json(Less likely): The plugin'spackage.jsonspecifies"import": "./dist/admin/index.mjs"which is relative to the plugin's root. Strapi should correctly resolve this when incorporating the plugin. - Strapi Build Logic Issue: There might be an issue with how Strapi 5's build process resolves paths for local plugins (
src/plugins) when generating the intermediate files like.strapi/client/app.jsor during the subsequent bundling step, especially in a containerized environment. The presence of./in the generated path (.../fdc-duplicate/./dist/...) is slightly unusual, although technically valid, and could hint at a path normalization issue within Strapi or its build tools. - Yarn Version Compatibility: You are using Yarn v1.22.22. Strapi 5 is relatively modern and relies on newer Node.js features and package manager capabilities, particularly around
exportsmaps (which your plugin uses). Yarn v1 is quite old and may not fully or correctly handle all modernexportsconfigurations or complex workspaces/path resolutions as expected by Strapi 5's build tools (like Webpack/Rollup configured by Strapi). Strapi often recommends using a newer Yarn version (like v3 or v4) managed bycorepack.
Proposed Solution: Upgrade Yarn
The most probable cause for a
Could not resolveerror involving complex paths and modernexportsin a relatively new framework version (Strapi 5) running on an older package manager (Yarn 1.x) is package manager incompatibility or limitations.Let's update the Dockerfile to use a recent Yarn version via
corepack(which is included in Node 20):FROM node:20-alpine as build RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1 WORKDIR /opt/app # Enable Corepack and specify Yarn version (e.g., yarn@stable will get the latest v3 or v4) # This prepares Yarn to be used and activates the specified version. RUN corepack enable && corepack prepare yarn@stable --activate # 1. Copy root dependency files first to leverage caching COPY package.json yarn.lock ./ # 2. Install root dependencies using the activated Yarn version # Use --immutable for reproducible builds in Docker RUN yarn config set network-timeout 600000 -g && yarn install --immutable # 3. Copy all application code (including src/plugins, config, etc.) # This ensures plugin package.json and code are present at /opt/app/src/plugins/... COPY . . # 4. Install dependencies *for each plugin* before building them # This will also use the activated Yarn version and install deps into src/plugins/*/node_modules RUN yarn install --cwd src/plugins/fdc-duplicate --immutable RUN yarn install --cwd src/plugins/fdc-material-symbols --immutable # Assuming this one also needs deps # 5. Build each plugin individually using the activated Yarn version # This creates the dist folders (e.g., /opt/app/src/plugins/fdc-duplicate/dist) RUN yarn --cwd src/plugins/fdc-duplicate build RUN yarn --cwd src/plugins/fdc-material-symbols build # 6. Run the main application build using the activated Yarn version # This step should now correctly resolve the plugin build outputs. RUN yarn build # --- Final Stage --- FROM node:20-alpine # Install only runtime dependencies required by the app (like libvips) RUN apk add --no-cache vips-dev WORKDIR /opt/app # Enable Corepack in the final stage if yarn commands are used later (e.g., in entrypoint for start) # This might not be strictly necessary if your entrypoint just uses `node dist/server.js` # but it's safe if `yarn start` or similar is used. RUN corepack enable && corepack prepare yarn@stable --activate # Copy build artifacts and necessary scripts from the build stage # This copies /opt/app from the build stage, including built files, node_modules, etc. COPY --from=build /opt/app ./ # Explicitly copy entrypoint/healthcheck if they are in a specific subdir like 'docker/' # If they are at the root of your build context, the `COPY --from=build /opt/app ./` above might already include them # assuming you copied them into /opt/app in the build stage with `COPY . .`. # To be explicit and safer: COPY docker/entrypoint.sh ./ COPY docker/healthcheck.js ./ RUN chmod +x entrypoint.sh EXPOSE 1337 ENTRYPOINT ["./entrypoint.sh"]Key Changes:
corepack enable && corepack prepare yarn@stable --activate: This is added early in the build stage to configure Node.js 20 to use a recent stable version of Yarn instead of the older default that comes with the Alpine package. This command needs internet access.yarn install --immutable: Added--immutabletoyarn installcommands. This is best practice in Docker builds to ensure your build fails if youryarn.lockfile isn't consistent withpackage.json, preventing potential hidden issues.- Applied Corepack to Final Stage: Added
corepacksetup to the final stage as well. This is necessary if yourentrypoint.shorhealthcheck.jsscript callsyarn(e.g.,yarn start). If they only callnode, it's not strictly needed, but harmless.
Try building your Docker image again with this updated Dockerfile. Using a newer Yarn version is the most likely fix for resolution issues involving modern JS features and build tools.
- Context: This error occurs during the main Strapi build process (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.