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
The error in your Dockerfile build process indicates that the
strapi-plugincommand is not found when runningyarn --cwd src/plugins/fdc-duplicate build. This is happening because thestrapi-pluginCLI tool, which is required to build Strapi plugins, is not installed in your build environment. Let's analyze the issue and provide a solution.Root Cause
The error message
/bin/sh: strapi-plugin: not foundsuggests that thestrapi-pluginpackage (or a similar dependency) is not available in the environment. This is likely because:- Missing Dependency: The
strapi-pluginCLI tool is not installed globally or as a dependency in your project. - Incorrect Build Command: The
strapi-plugin buildcommand might not be the correct way to build your plugin, depending on your Strapi version and setup. - Environment Issue: The build environment might not have the necessary tools or dependencies to execute the plugin build process.
Solution
To fix this issue, you need to ensure that the necessary tools and dependencies are available in your build environment. Below are the steps to resolve the issue:
1. Install
@strapi/clior Required ToolsThe
strapi-plugincommand might not exist as a standalone package. Instead, Strapi plugins are typically built using the Strapi CLI or other tools provided by Strapi. You need to ensure that the@strapi/clipackage (or equivalent) is installed globally in your build environment.Modify your Dockerfile to install the Strapi CLI globally:
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 global add @strapi/cli # Add this line to install Strapi CLI globally 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"]2. Update Plugin Build Command
The
strapi-plugin buildcommand in your plugin'spackage.jsonmight not be correct. Based on the Strapi documentation, plugins are typically built using the Strapi CLI or by running a custom build script. Check thescriptssection of your plugin'spackage.json(provided in your question):"scripts": { "build": "strapi-plugin build", "watch": "strapi-plugin watch", "watch:link": "strapi-plugin watch:link", "verify": "strapi-plugin verify" }The
strapi-plugin buildcommand is not a standard Strapi command. Instead, Strapi plugins are usually built using a custom build process (e.g., usingtscfor TypeScript orbabelfor JavaScript). You need to ensure that thebuildscript in your plugin'spackage.jsonis correctly set up to build the plugin.For example, if your plugin uses TypeScript, the
buildscript might look like this:"scripts": { "build": "tsc -p tsconfig.json", "watch": "tsc -w", "watch:link": "strapi-plugin watch:link", "verify": "strapi-plugin verify" }If your plugin uses JavaScript, you might need to use a tool like
babelorwebpackto transpile and bundle the code. Update thebuildscript accordingly.3. Ensure Plugin Dependencies Are Installed
Your plugin's
package.jsonlists several dependencies and peer dependencies. Ensure that these are installed in the build environment. When you runyarn installin the root of your project, it might not automatically install the dependencies for the plugins insrc/plugins/. You need to explicitly install the dependencies for each plugin.Modify your Dockerfile to install the plugin dependencies before building:
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 global add @strapi/cli RUN yarn config set network-timeout 600000 -g && yarn install # Install dependencies for each plugin RUN yarn --cwd src/plugins/fdc-duplicate install RUN yarn --cwd src/plugins/fdc-material-symbols 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"]4. Verify Plugin Build Process
Before running the Docker build, test the plugin build process locally to ensure it works. Navigate to the plugin directory (
src/plugins/fdc-duplicate) and run:yarn install yarn buildIf the build fails locally, it indicates an issue with the plugin's
package.jsonor build configuration. Fix any errors before proceeding with the Docker build.5. Debugging Tips
If the issue persists, here are some debugging tips:
- Check Installed Packages: Add a step in your Dockerfile to list globally installed Yarn packages to verify that
@strapi/cliis installed:RUN yarn global list - Check Plugin Build Output: Add a step to print the contents of the plugin directory before building to ensure all files are present:
RUN ls -la src/plugins/fdc-duplicate - Verbose Build Output: Run the build command with verbose output to get more details:
RUN yarn --cwd src/plugins/fdc-duplicate build --verbose
6. Alternative Build Approach
If the plugin build process is still failing, consider building the plugins as part of the main
yarn buildcommand for your Strapi application. Strapi's build process typically includes building all plugins automatically. In this case, you can remove the explicit plugin build steps from your 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 COPY package.json yarn.lock ./ COPY src/plugins/ src/plugins/ RUN yarn global add node-gyp RUN yarn global add @strapi/cli 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 ./ # Build the entire Strapi application (including plugins) 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"]This approach relies on Strapi's built-in build process to handle plugin compilation, which is often more reliable.
Final Notes
- Strapi Version Compatibility: Ensure that the versions of
@strapi/strapi,@strapi/cli, and other dependencies in your project are compatible with each other. Check the Strapi documentation for version compatibility. - Plugin Development: If you are developing the
fdc-duplicateplugin, consider following the official Strapi plugin development guide to ensure your plugin is structured correctly. - Docker Build Cache: If you make changes to your Dockerfile, ensure you rebuild the Docker image without using the cache to apply the changes:
docker build --no-cache -t your-image-name .
By following the steps above, you should be able to resolve the
strapi-plugin: not founderror and successfully build your Strapi application with plugins in Docker. - Missing Dependency: The
- 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
The error you're encountering during the Strapi admin panel build process indicates that Rollup (the bundler used by Strapi to build the admin panel) is unable to resolve the
index.mjsfile for yourfdc-duplicateplugin. This is a common issue when building Strapi plugins, especially if the plugin's build process or file structure is not set up correctly. Let's analyze the issue and provide a step-by-step solution.
Root Cause
The error message:
Could not resolve "../../src/plugins/fdc-duplicate/./dist/admin/index.mjs" from ".strapi/client/app.js"suggests the following issues:
-
Missing or Incorrect Plugin Build Output:
- Strapi expects the
fdc-duplicateplugin to have a builtindex.mjsfile in thedist/admin/directory of the plugin. This file is typically generated during the plugin's build process. - If the plugin's build process is not correctly set up, the
dist/admin/index.mjsfile will not exist, causing the admin panel build to fail.
- Strapi expects the
-
Incorrect Plugin
exportsConfiguration:- The
exportsfield in your plugin'spackage.jsonspecifies where Strapi should look for the plugin's admin code (./dist/admin/index.mjs). If this path does not match the actual build output, the build will fail.
- The
-
Plugin Build Process Not Running:
- The plugin's build process (e.g.,
yarn buildin the plugin directory) might not be running correctly, or it might not be generating the expected output.
- The plugin's build process (e.g.,
-
File Structure Mismatch:
- The file structure of your plugin might not match Strapi's expectations for a plugin, particularly in terms of where the admin code is located and how it is built.
Solution
To resolve this issue, you need to ensure that the
fdc-duplicateplugin is correctly structured, its build process is working, and the expected build output (dist/admin/index.mjs) is generated. Below are the steps to fix the issue:
1. Verify Plugin File Structure
Strapi plugins have a specific file structure, especially for the admin panel code. Ensure your
fdc-duplicateplugin (located insrc/plugins/fdc-duplicate/) has the following structure:src/plugins/fdc-duplicate/ ├── admin/ │ └── src/ │ └── index.js # Entry point for admin panel code ├── package.json # Plugin's package.json ├── tsconfig.json # (Optional) If using TypeScript └── ... # Other plugin files (e.g., server code)- The
admin/src/index.jsfile is the entry point for the admin panel code of your plugin. This file is required for Strapi to load your plugin into the admin panel. - During the build process, this file should be transpiled and bundled into
dist/admin/index.mjs.
If your plugin is using TypeScript, the admin code might be in
admin/src/index.tsinstead ofindex.js. In this case, ensure you have a propertsconfig.jsonfile to handle TypeScript compilation.
2. Update Plugin
package.jsonYour plugin's
package.jsonspecifies how the plugin's admin code is exposed to Strapi via theexportsfield. Based on the error, Strapi is looking fordist/admin/index.mjs, but this file is not being generated.Here is the relevant part of your
package.json:"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" } }- The
strapi-adminexport specifies that the admin panel code should be built intodist/admin/index.mjs(for ES modules) anddist/admin/index.js(for CommonJS). - Ensure that your plugin's build process generates these files in the
dist/admin/directory.
If your plugin is not generating these files, the issue lies in the build process, which we will fix in the next step.
3. Fix Plugin Build Process
The error indicates that the
dist/admin/index.mjsfile is not being generated. This is likely because the plugin's build process is not set up correctly. Let's fix this by updating thescriptssection of your plugin'spackage.jsonand ensuring the build process works.Step 3.1: Update
scriptsinpackage.jsonThe
scriptssection of your plugin'spackage.jsoncurrently looks like this:"scripts": { "build": "strapi-plugin build", "watch": "strapi-plugin watch", "watch:link": "strapi-plugin watch:link", "verify": "strapi-plugin verify" }The
strapi-plugin buildcommand is not a standard Strapi command. Instead, you need to define a custom build process to transpile and bundle your plugin's admin code. Here’s how to fix it:- If your plugin uses JavaScript, you need to use a bundler like Rollup or Webpack to generate the
dist/admin/index.mjsfile. - If your plugin uses TypeScript, you need to use
tsc(TypeScript compiler) to transpile the code.
For simplicity, let's assume your plugin uses JavaScript. You can use Rollup to bundle the admin code. Update the
scriptssection as follows:"scripts": { "build": "rollup -c", "watch": "rollup -c -w", "watch:link": "strapi-plugin watch:link", "verify": "strapi-plugin verify" }Then, create a
rollup.config.jsfile in the root of your plugin (src/plugins/fdc-duplicate/rollup.config.js) with the following content:import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import babel from '@rollup/plugin-babel'; import terser from '@rollup/plugin-terser'; export default [ { input: 'admin/src/index.js', // Entry point for admin code output: [ { file: 'dist/admin/index.mjs', // ES module output format: 'esm', }, { file: 'dist/admin/index.js', // CommonJS output format: 'cjs', }, ], plugins: [ resolve(), // Resolve node_modules dependencies commonjs(), // Convert CommonJS modules to ES modules babel({ babelHelpers: 'bundled' }), // Transpile modern JavaScript terser(), // Minify the output ], external: [ 'react', 'react-dom', 'react-router-dom', 'styled-components', '@strapi/design-system', '@strapi/icons', 'react-intl', ], // Externalize peer dependencies }, ];Next, install the required Rollup plugins as dev dependencies in your plugin:
cd src/plugins/fdc-duplicate yarn add --dev @rollup/plugin-node-resolve @rollup/plugin-commonjs @rollup/plugin-babel @rollup/plugin-terser rollupNow, test the build process locally:
cd src/plugins/fdc-duplicate yarn buildAfter running this command, check if the
dist/admin/index.mjsanddist/admin/index.jsfiles are generated in thesrc/plugins/fdc-duplicate/dist/admin/directory. If they are, the plugin build process is working correctly.Step 3.2: If Using TypeScript
If your plugin uses TypeScript (e.g.,
admin/src/index.ts), update thescriptssection to usetsc:"scripts": { "build": "tsc -p tsconfig.json", "watch": "tsc -w", "watch:link": "strapi-plugin watch:link", "verify": "strapi-plugin verify" }Ensure you have a
tsconfig.jsonfile in the root of your plugin (src/plugins/fdc-duplicate/tsconfig.json) with the following content:{ "compilerOptions": { "target": "esnext", "module": "esnext", "outDir": "dist", "rootDir": ".", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "moduleResolution": "node", "jsx": "react-jsx", "declaration": true }, "include": ["admin/src/**/*", "server/src/**/*"], "exclude": ["node_modules", "dist"] }Install TypeScript as a dev dependency in your plugin:
cd src/plugins/fdc-duplicate yarn add --dev typescriptTest the build process locally:
cd src/plugins/fdc-duplicate yarn buildCheck if the
dist/admin/index.mjsfile is generated. Note that TypeScript typically generates.jsfiles, not.mjs. If Strapi requires.mjs, you may need to use Rollup (as shown in Step 3.1) to bundle the TypeScript output into.mjsformat.
4. Update Dockerfile
Your Dockerfile runs the plugin build process explicitly for each plugin (
yarn --cwd src/plugins/fdc-duplicate build). Ensure that the plugin's dependencies are installed and the build process is executed correctly. Update your Dockerfile to include the plugin build dependencies: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 # Install dependencies for each plugin RUN yarn --cwd src/plugins/fdc-duplicate install RUN yarn --cwd src/plugins/fdc-material-symbols install COPY src/ src/ COPY public/ public/ COPY database/ database/ COPY config/ config/ COPY tsconfig.json ./ COPY favicon.png ./ COPY tsconfig.json ./ # Build each plugin RUN yarn --cwd src/plugins/fdc-duplicate build RUN yarn --cwd src/plugins/fdc-material-symbols build # Build the entire Strapi application 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"]If the plugin build process is working correctly locally, this Dockerfile should work without errors.
5. Debugging Tips
If the issue persists, here are some debugging tips to help identify the root cause:
-
Check Plugin Build Output: Add a step in your Dockerfile to list the contents of the plugin's
dist/directory after building the plugin:RUN yarn --cwd src/plugins/fdc-duplicate build RUN ls -la src/plugins/fdc-duplicate/dist/admin/This will help you verify if the
index.mjsfile is being generated. -
Run Build with Debug Mode: The error message suggests running the build with
--debugfor more information. Modify theyarn buildcommand in your Dockerfile to include the--debugflag:RUN yarn build --debugThis will provide more detailed error messages.
-
Test Plugin Build Locally: Before running the Docker build, test the plugin build process locally to ensure it works:
cd src/plugins/fdc-duplicate yarn install yarn buildIf the build fails locally, fix the issue before proceeding with the Docker build.
-
Check Strapi Version Compatibility: Ensure that the versions of
@strapi/strapi,@strapi/design-system, and other dependencies in your project are compatible with each other. Check the Strapi documentation for version compatibility. -
Verify Plugin Admin Code: Ensure that the
admin/src/index.js(orindex.ts) file exists and contains valid code. For example, a minimalindex.jsfile for a Strapi plugin might look like this:export default { bootstrap(app) { console.log('FDC Duplicate plugin bootstrapped'); }, };
6. Alternative Approach: Let Strapi Build Plugins
If you are unable to fix the plugin build process, consider letting Strapi handle the plugin build as part of the main
yarn buildcommand. Strapi's build process typically includes building all plugins automatically. In this case, you can remove the explicit plugin build steps from your 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 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 ./ # Build the entire Strapi application (including plugins) 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"]This approach relies on Strapi's built-in build process to handle plugin compilation, which is often more reliable.
Final Notes
- Strapi Plugin Development Guide: If you are developing the
fdc-duplicateplugin, consider following the official Strapi plugin development guide to ensure your plugin is structured correctly: Strapi Plugin Development. - Docker Build Cache: If you make changes to your Dockerfile or plugin code, ensure you rebuild the Docker image without using the cache to apply the changes:
docker build --no-cache -t your-image-name . - Minimal Reproducible Example: If the issue persists, consider creating a minimal reproducible example of your plugin and sharing it (e.g., via GitHub) so that others can help debug the issue.
By following the steps above, you should be able to resolve the
Could not resolve "../../src/plugins/fdc-duplicate/./dist/admin/index.mjs"error and successfully build your Strapi application with plugins in Docker. -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.