ModuleNotFoundError: Module not found: Error: Can't resolve 'react-grid-dnd' in ……

System Information
  • Strapi Version: 4.2.3
  • Operating System: ubuntu 22.04.1 LTS
  • Database: sqlite
  • Node Version: 14.19.3
  • Yarn Version: 1.22.19

Hello

I have a problem of importing a module during a strapi build on one of our home-made plugins.

#0 0.507 yarn run v1.22.19                                                                                                                                                                                 
#0 0.559 $ strapi build                                                                                                                                                                                    
#0 2.480 Building your admin UI with production configuration ...                                                                                                                                          
#0 3.463 ℹ Compiling Webpack                                                                                                                                                                               
#0 10.14 ModuleNotFoundError: Module not found: Error: Can't resolve 'react-grid-dnd' in '/srv/strapi/src/plugins/pagelist/admin/src/pages/EditOrderProductsPage'
#0 10.14     at /srv/node_modules/webpack/lib/Compilation.js:2016:28
#0 10.14     at /srv/node_modules/webpack/lib/NormalModuleFactory.js:798:13
#0 10.14     at eval (eval at create (/srv/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)

We have in our company a Strapi project with home-made plugins (thanks Strapi!). The project runs on a server without any problem. Strapi is in a Docker container.

I need to move this project to a new server. When I rebuild the Strapi container, I get this error and I confess I don’t understand why it appears now. On the other server, during the development phases, this error did not appear.
Thank you very much for your feedback.

Current server: ubuntu 20.04.5
New server: ubuntu 22.04.1 LTS

Dockerfile:
It is the RUN yarn build command that triggers this error.

FROM node:14 as strapi-prod
# Installing libvips-dev for sharp compatability
RUN apt-get update && apt-get install -y libvips-dev
 
ENV NODE_ENV=production
 
WORKDIR /srv/
 
COPY ./package.json ./
 
COPY ./yarn.lock ./
 
ENV PATH /srv/node_modules/.bin:$PATH
 
ENV YARN_CACHE_FOLDER=/usr/local/yarn-cache
VOLUME /usr/local/yarn-cache
 
RUN yarn config set network-timeout 600000 -g
 
RUN yarn install
 
WORKDIR /srv/strapi
 
COPY . .
 
RUN yarn build
 
CMD ["yarn", "start"]
 
EXPOSE 1337

FROM strapi-prod as strapi-dev
 
ENV NODE_ENV=development
 
CMD ["yarn", "develop"]

package.json at the root of the project

{
 "name": "strapietik",
 "private": true,
 "version": "0.1.0",
 "description": "Strapi for my company",
 "scripts": {
   "develop": "strapi develop",
   "start": "strapi start",
   "build": "strapi build",
   "strapi": "strapi",
   "lint": "eslint .",
   "lint:fix": "eslint . --fix"
 },
 "devDependencies": {
   "@strapi-community/eslint-config": "^0.2.0",
   "@strapi-community/eslint-config-admin": "^0.2.0",
   "eslint": "^8.11.0"
 },
 "dependencies": {
   "@ckeditor/ckeditor5-react": "^4.0.1",
   "@strapi/plugin-documentation": "4.2.3",
   "@strapi/plugin-i18n": "4.2.3",
   "@strapi/plugin-users-permissions": "4.2.3",
   "@strapi/provider-upload-aws-s3": "^4.2.0",
   "@strapi/strapi": "4.2.3",
   "base-64": "^1.0.0",
   "moment": "^2.29.3",
   "slugify": "^1.6.5",
   "sqlite3": "5.0.2",
   "strapi-plugin-populate-deep": "^0.1.2",
   "strapi-plugin-rest-cache": "^4.2.4",
   "strapi-provider-rest-cache-memory": "^4.2.4"
 },
 "author": {
   "name": "My company"
 },
 "strapi": {},
 "engines": {
   "node": ">=12.x.x <=16.x.x",
   "npm": ">=6.0.0"
 },
 "license": "MIT"
}

Package.json of the concerned plugin.

# strapi/src/plugins/pagelist
 
{
 "name": "pagelist",
 "version": "0.0.0",
 "description": "This is the description of the plugin.",
 "strapi": {
   "name": "Pages listes",
   "description": "Set of helpers for page lists admin",
   "kind": "plugin"
 },
 "dependencies": {
   "classnames": "^2.3.1",
   "meilisearch": "^0.25.1",
   "react-gesture-responder": "^2.1.0",
   "react-grid-dnd": "^2.1.2"
 },
 "author": {
   "name": "dev Team"
 },
 "maintainers": [
   {
     "name": "dev Team"
   }
 ],
 "engines": {
   "node": ">=12.x.x <=16.x.x",
   "npm": ">=6.0.0"
 },
 "license": "My company"
}

The file where I import the module.

import React, { useState, useEffect }  from 'react';
import {  useParams } from "react-router-dom";
 
import { LoadingIndicatorPage } from '@strapi/helper-plugin';
 
// utils
import { request } from '@strapi/helper-plugin';
import { swap } from "react-grid-dnd";
 
function EditOrderProductsPage() {
// .......

Did you found any solution? I’m facing a similiar problem.

$ npm run gcp-build

> institutional-cms@0.4.2 gcp-build
> strapi build

Building your admin UI with development configuration...

● Webpack █████████████████████████ building (62%) 2/2 entries 2985/3106 dependencies 516/1465 modules 374 active
 node_modules\date-fns\differenceInWeeks\index.js

ModuleNotFoundError: Module not found: Error: Can't resolve '@strapi/icons/CarretDown' in 'C:\Users\xxx\www\xxx-cms\strapi\node_modules\@strapi\design-system\dist\Select'
Did you mean 'CarretDown.js'?
BREAKING CHANGE: The request '@strapi/icons/CarretDown' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.