Skip to content
The Chat Archive
gemini-2.5-flash-preview-04-17· Google LMArena Human Preference 140K

FROM node:20-alpine as build RUN apk update && apk add --no-cache build-base gcc…

  1. 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

  2. Assistant

    Okay, the error message /bin/sh: strapi-plugin: not found is the key.

    This means that when Yarn tried to execute the build script defined in your src/plugins/fdc-duplicate/package.json ("build": "strapi-plugin build"), the command strapi-plugin could not be found in the container's PATH.

    Why did this happen? The strapi-plugin command is provided by the @strapi/sdk-plugin or similar Strapi development SDK package. When you run yarn build within the plugin's directory (src/plugins/fdc-duplicate), Yarn looks for executable scripts in node_modules/.bin/ inside that directory (or in parent directories up to the project root).

    Your Dockerfile installs the root project dependencies (yarn install at /opt/app), but it doesn't explicitly install the dependencies for the plugin itself located at src/plugins/fdc-duplicate. Even though @strapi/sdk-plugin might be a peerDependency or a dependency of the main Strapi project, the plugin's build script needs to find it relative to the plugin's context, typically in its own node_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 install specifically within the plugin's directory after you've copied the plugin's code (which includes its package.json and potentially yarn.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:

    1. Consolidated COPY: Instead of multiple COPY commands for src, public, database, etc., a single COPY . . after the root yarn install is used. This copies the entire source code, including the src/plugins/ directories with their package.json files. This is a more common and often more cache-efficient pattern after dependency installation.
    2. Added Plugin yarn install: The critical fix is adding RUN yarn install --cwd src/plugins/fdc-duplicate (and for the other plugin fdc-material-symbols). This command changes the directory to the plugin's source folder (/opt/app/src/plugins/fdc-duplicate) and runs yarn install there. This installs the plugin's own dependencies (including @strapi/sdk-plugin likely via peer dependencies or devDependencies) into src/plugins/fdc-duplicate/node_modules/.
    3. Plugin Build After Install: Now, when RUN yarn --cwd src/plugins/fdc-duplicate build is executed, Yarn can find the strapi-plugin executable in the newly created node_modules/.bin/ directory within the plugin's folder.
    4. Entrypoint/Healthcheck Copy: Added COPY . . in the build stage assumes docker/entrypoint.sh and docker/healthcheck.js are at the root of your build context. The final stage then copies all of /opt/app from the build stage, including these scripts.

    Apply these changes to your Dockerfile and try building again. This should resolve the "strapi-plugin: not found" error.

  3. 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.

  4. Assistant

    Okay, the previous error (strapi-plugin: not found) was resolved by running yarn install within the plugin directory before attempting to build the plugin.

    Now, you're facing a new error during the main yarn build step, 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.js
    

    Explanation of the Error:

    1. Context: This error occurs during the main Strapi build process (yarn build in /opt/app), which includes bundling the admin panel.
    2. 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.
    3. 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.mjs relative to /opt/app/.strapi/client/app.js.
    4. 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.
    5. 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 RUN command).
    • Incorrect Path in Plugin package.json (Less likely): The plugin's package.json specifies "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.js or 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 exports maps (which your plugin uses). Yarn v1 is quite old and may not fully or correctly handle all modern exports configurations 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 by corepack.

    Proposed Solution: Upgrade Yarn

    The most probable cause for a Could not resolve error involving complex paths and modern exports in 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:

    1. 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.
    2. yarn install --immutable: Added --immutable to yarn install commands. This is best practice in Docker builds to ensure your build fails if your yarn.lock file isn't consistent with package.json, preventing potential hidden issues.
    3. Applied Corepack to Final Stage: Added corepack setup to the final stage as well. This is necessary if your entrypoint.sh or healthcheck.js script calls yarn (e.g., yarn start). If they only call node, 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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.