minio / minio-js

MinIO Client SDK for Javascript
https://docs.min.io/docs/javascript-client-quickstart-guide.html
Apache License 2.0
933 stars 274 forks source link

ReferenceError: require is not defined #867

Closed rayguang closed 3 years ago

rayguang commented 3 years ago

Describe the bug I am adding a new cloud storage support by using min.io (https://docs.min.io/docs/javascript-client-api-reference.html). After running npm start, no particular error. When I go to http://localhost, received the following error:

`ReferenceError: require is not defined Module../node_modules/minio/node_modules/async/dist/async.mjs http://localhost/static/js/0.chunk.js:215453:30 __webpack_require__ src/app/webpack/bootstrap:782 779 | }; 780 | 781 | // Execute the module function

782 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId)); | ^ 783 | 784 | // Flag the module as loaded 785 | module.l = true; View compiled fn src/app/webpack/bootstrap:150 147 | ); 148 | hotCurrentParents = []; 149 | } 150 | return webpack_require(request); | ^ 151 | }; 152 | var ObjectFactory = function ObjectFactory(name) { 153 | return { View compiled ▶ 2 stack frames were collapsed. webpack_require src/app/webpack/bootstrap:782 779 | }; 780 | 781 | // Execute the module function 782 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId)); | ^ 783 | 784 | // Flag the module as loaded 785 | module.l = true; View compiled fn src/app/webpack/bootstrap:150 147 | ); 148 | hotCurrentParents = []; 149 | } 150 | return webpack_require(request); | ^ 151 | }; 152 | var ObjectFactory = function ObjectFactory(name) { 153 | return { View compiled ▶ 2 stack frames were collapsed. webpack_require src/app/webpack/bootstrap:782 779 | }; 780 | 781 | // Execute the module function 782 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId)); | ^ 783 | 784 | // Flag the module as loaded 785 | module.l = true;`

To Reproduce I have created several files and made most changes in minioStorage.ts by replacing the functions similar to azureStorage.ts with minio API

Expected behavior A clear and concise description of what you expected to happen. A sample of the code listed below:

`import { IStorageProvider } from "./storageProviderFactory"; import { IAsset, AssetType, StorageType } from "../../models/applicationState"; import { AssetService } from "../../services/assetService"; import * as minio from "minio"; import { Bounce } from "react-toastify";

//var minio = require("minio");

const minioClient = new minio.Client({ endPoint: "localhost", port: 9000, useSSL: false, accessKey: "xxxx", secretKey: "xxxxxxx" });

/**

export class MinioStorage implements IStorageProvider { /**

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

Any hint is welcome! Thanks.

prakashsvmx commented 3 years ago

This can be tested in a react app. Example: https://github.com/prakashsvmx/minio-js-web-browser-example