0

• Have installed strapi via the following command:

npx create-strapi-app my-project --quickstart
  • As a result, have the following structure:
[bash myproject]$ tree -L 1
.
├── README.md
├── admin
├── api
├── build
├── config
├── extensions
├── favicon.ico
├── node_modules
├── package-lock.json
├── package.json
├── public
└── yarn.lock

With this goal, created ./admin/node_modules and installed express, fs, net packages in it. Also, have used default admin.config.js, https://strapi.gitee.io/documentation/3.0.0-beta.x/admin-panel/custom-webpack-config.html :

[bash admin]$ tree -L 1
.
├── admin.config.js
├── node_modules
├── package-lock.json
└── src

2 directories, 2 files
[bash admin]$ tree -L 1 node_modules/
node_modules/
├── accepts
├── array-flatten
├── body-parser
├── bytes
├── content-disposition
├── content-type
├── cookie
├── cookie-signature
├── debug
├── depd
├── destroy
├── ee-first
├── encodeurl
├── escape-html
├── etag
├── express
├── finalhandler
├── forwarded
├── fresh
├── fs
├── http-errors
├── iconv-lite
├── inherits
├── ipaddr.js
├── media-typer
├── merge-descriptors
├── methods
├── mime
├── mime-db
├── mime-types
├── ms
├── negotiator
├── on-finished
├── parseurl
├── path-to-regexp
├── proxy-addr
├── qs
├── range-parser
├── raw-body
├── safe-buffer
├── safer-buffer
├── send
├── serve-static
├── setprototypeof
├── statuses
├── toidentifier
├── type-is
├── unpipe
├── utils-merge
└── vary

50 directories, 0 files

[bash node_modules]$ tree -L 1 destroy/
destroy/
├── LICENSE
├── README.md
├── index.js
└── package.json

(Snippet of an original app.js)

....

import basename from "./utils/basename";
import injectReducer from "./utils/injectReducer";
import injectSaga from "./utils/injectSaga";
import Strapi from "./utils/Strapi";

// Import root component
import App from "./containers/App";
// Import Language provider
import LanguageProvider from "./containers/LanguageProvider";

import configureStore from "./configureStore";
import { SETTINGS_BASE_URL } from "./config";

// Import i18n messages
import { translationMessages, languages } from "./i18n";

import history from "./utils/history";

import plugins from "./plugins";

// const PORT = 8181;
// const HOST = "0.0.0.0";
// // app
// const app = express();
// app.get("/endpoint", (req, res) => {
//   res.send("customer API is being hit");
// });
// app.listen(PORT, HOST);
// console.log(`Running on http://${HOST}:${PORT}`);

// import express from '../node_modules/express' // Tried to place here, same error

const strapi = Strapi();

const pluginsReducers = {};
const pluginsToLoad = [];

import fs from '../node_modules/fs'
import express from '../node_modules/express'

Object.keys(plugins).forEach((current) => {
  const registerPlugin = (plugin) => {
    strapi.registerPlugin(plugin);

    return plugin;
  };
  const currentPluginFn = plugins[current];

  // By updating this by adding required methods
  // to load a plugin you need to update this file
  // strapi-generate-plugins/files/admin/src/index.js needs to be updated
  const plugin = currentPluginFn({
    registerComponent: strapi.componentApi.registerComponent,
    registerField: strapi.fieldApi.registerField,
    registerPlugin,
    settingsBaseURL: SETTINGS_BASE_URL || "/settings",
    middlewares: strapi.middlewares,
  });

.....

Upon attempt to build the package via npm run build, an error message showing up:


....

 「wds」: 404s will fallback to /admin/
Starting the development server...

Admin development at http://localhost:8000/admin/
 



 ERROR  Failed to compile with 7 errors                  21:49:22

These dependencies were not found:

* fs in ./.cache/admin/node_modules/destroy/index.js, ./.cache/admin/node_modules/etag/index.js and 3 others
* net in ./.cache/admin/node_modules/express/lib/request.js

To install them, you can run: npm install --save fs net


This relative module was not found:

* ../node_modules/fs in ./.cache/admin/src/app.js
 WAIT  Compiling...                                      21:49:22

 ERROR  Failed to compile with 7 errors                  21:49:29

These dependencies were not found:

* fs in ./.cache/admin/node_modules/destroy/index.js, ./.cache/admin/node_modules/etag/index.js and 3 others
* net in ./.cache/admin/node_modules/express/lib/request.js

To install them, you can run: npm install --save fs net


This relative module was not found:

* ../node_modules/fs in ./.cache/admin/src/app.js

Quesitons:

• Any suggestions on why this error is showing up, at this stage?

• I have tried to use other, NPM Packages, and was getting similar error, when attempting to invoke their methods, by customizing the app.js, so, I thought, it is something to do with the webpack "package path chaging"

• Have tried to ignore the package by means of webpack, but, it didn't help, is there a way to avoid this error, by means of webpack?

NOTE: running npm install --save fs net is not helping, neither from <project_root>/admin/src/ nor <project_root>

NOTE: I have reviewed this document: https://strapi.io/documentation/developer-docs/latest/development/admin-customization.html#customization-options, which suggests to leverage <project_root>/extensions folder, in order to create custom extension with it's own modules, however, have done that, and, upon start, exact same error is coming up.

NOTE: I have reviewed this doc: Webpack Express Cannot Resolve Module 'fs', Request Dependency is Expression, which is showing similar issue, however, due to the point, that there is no webpack.config.js for strapi, as there is only ./admin/src/admin.config.js, in which I have tried to put config.plugins.push(webpack.target('node')); , which did not work...

ENV: macos64bit, node12.22.1, npm6.14.12, strapi3.6.3

readonly
  • 79
  • 7

0 Answers0